MCQs
Total Questions : 20
| Page 2 of 2 pages
Answer: Option C. -> 3 and 6
Question 12. What will happen after compiling this program code?abstract class MyClass{ //line 1 private int a, b; public void call(int a, int b){ this.a = a; this.b = b; System.out.print(a+b); }}public class Test{ public static void main(String args[]){ MyClass m = new MyClass(); //line 2 m.call(12,25); }}
Answer: Option C. -> Compilation error due to line 2
Answer: Option B. -> None of these
Question 15. Interface Base{ boolean m1 (); byte m2(short s);}which two code fragments will compile?1. interface Base2 implements Base {}2. abstract class Class2 extends Base { public boolean m1(){ return true; }}3. abstract class Class2 implements Base {}4. abstract class Class2 implements Base { public boolean m1(){ return (7 > 4); }}5. abstract class Class2 implements Base { protected boolean m1(){ return (5 > 7) }}
Answer: Option A. -> 3 and 4
Question 16. What will be the output when the following program is compiled and executed?abstract class TestAbstract{ String my_name; String myName(){ my_name = "Examveda"; return my_name; } abstract void display();}public class Test extends TestAbstract{ void display(){ String n = myName(); System.out.print("My name is "+ n); } public static void main(String args[]){ Test t = new Test(); t.display(); }}
Answer: Option B. -> Program will compile and execute successfully and prints
Answer: Option A. -> Compile with error
Question 18. What happens if the following program is compiled and executed?interface MyInterface{ void display();}interface MySubInterface extends MyInterface{ void display();}public class Test implements MySubInterface{ public void display(){ System.out.print("Welcome to Examveda."); } public static void main(String args[]){ Test t = new Test(); t.display(); }}
Answer: Option C. -> The code will compile and execute successfully showing the output Welcome to Examians.
Answer: Option D. -> A
Answer: Option A. -> Compilation fails due to an error on lines 2