Sail E0 Webinar

MCQs

Total Questions : 20 | Page 2 of 2 pages
Question 11. 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) }}
  1.    1 and 2
  2.    2 and 3
  3.    3 and 4
  4.    1 and 3
  5.    4 and 5
 Discuss Question
Answer: Option C. -> 3 and 4
Question 12. Which two of the following are legal declarations for abstract classes and interfaces?
1. final abstract class Test {}
2. public static interface Test {}
3. final public class Test {}
4. protected abstract class Test {}
5. protected interface Test {}
6. abstract public class Test {}
  1.    1 and 2
  2.    2 and 4
  3.    3 and 5
  4.    5 and 6
  5.    3 and 6
 Discuss Question
Answer: Option E. -> 3 and 6
Question 13. 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);
}
}
  1.    Successful run and print 37
  2.    Compilation error due to line 1
  3.    Compilation error due to line 2
  4.    Runtime error
  5.    None of these
 Discuss Question
Answer: Option C. -> Compilation error due to line 2
Question 14. Interface Test{
int p = 10; //line 1
public int q = 20; //line 2
public static int r = 30; //line 3
public static final int s = 40; //line 4
}
Which of the above line will give compilation error?
  1.    1
  2.    2
  3.    3
  4.    4
  5.    None of these
 Discuss Question
Answer: Option E. -> None of these
Question 15. Runnable is a _____ .
  1.    class
  2.    abstract class
  3.    interface
  4.    vaiable
  5.    method
 Discuss Question
Answer: Option C. -> interface
Question 16. What is the output for the below code ?
interface A{
public void printValue();
}
1. public class Test{
2. public static void main (String[] args){
3. A a1 = new A(){
4. public void printValue(){
5. System.out.println("A");
6. }
7. };
8. a1.printValue();
9. }
10. }
  1.    Compilation fails due to an error on line 3
  2.    A
  3.    Compilation fails due to an error on line 8
  4.    null
  5.    None of these
 Discuss Question
Answer: Option B. -> A
Question 17. What will be the output for the below code ?
public interface TestInf{
int i =10;
}
public class Test{
public static void main(String... args){
TestInf.i=12;
System.out.println(TestInf.i);
}
}
  1.    Compile with error
  2.    10
  3.    12
  4.    Runtime Exception
  5.    None of these
 Discuss Question
Answer: Option A. -> Compile with error
Question 18. What will be the output?
1. public interface InfA{
2. protected String getName();
3. }
public class Test implements InfA{
public String getName(){
return "test-name";
}
public static void main (String[] args){
Test t = new Test();
System.out.println(t.getName());
}
}
  1.    test-name
  2.    Compilation fails due to an error on lines 2
  3.    Compilation fails due to an error on lines 1
  4.    Compilation succeed but Runtime Exception
  5.    None of these
 Discuss Question
Answer: Option B. -> Compilation fails due to an error on lines 2
Question 19. 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();
}
}
  1.    The code will lead to a compilation error as declaration of the display method has been provided in two interface.
  2.    The code will lead to a compilation error due to public modifier while declaring the display method.
  3.    The code will compile and execute successfully showing the output Welcome to Examveda.
  4.    The code will lead to a compilation error as the display method is not declared as abstract.
  5.    None of these
 Discuss Question
Answer: Option C. -> The code will compile and execute successfully showing the output Welcome to Examveda.
Question 20. 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();
}
}
  1.    Program will compile and execute successfully and prints
  2.    Compilation error as class can not be declared as abstract.
  3.    Program compiles but leads to runtime exception.
  4.    Compilation error occurs as the abstract class TestAbstract contains a non-abstract method.
  5.    None of these
 Discuss Question
Answer: Option A. -> Program will compile and execute successfully and prints

Latest Videos

Latest Test Papers