Sail E0 Webinar

MCQs

Total Questions : 13 | Page 1 of 2 pages
Question 1. What is the result of compiling and running the following code?class Base{ public Base(){ System.out.print("Base"); }}public class Derived extends Base{ public Derived(){ this("Examveda"); System.out.print("Derived"); } public Derived(String s){ System.out.print(s); } public static void main(String[] args){ new Derived(); }}
  1.    Compilation Error
  2.    BaseExamiansDerived
  3.    ExamiansDerivedBase
  4.    ExamiansDerived
  5.    ExamiansBaseDerived
 Discuss Question
Answer: Option B. -> BaseExamiansDerived
Question 2. What is the output of the following program code?abstract class C1{public C1(){ System.out.print(1); } } class C2 extends C1{ public C2(){ System.out.print(2); } } class C3 extends C2{ public C3(){ System.out.println(3); } } public class Test{ public static void main(String[] a){ new C3(); } }
  1.    321
  2.    23
  3.    123
  4.    12
 Discuss Question
Answer: Option C. -> 123
Question 3. Which of the following is true?1. A class can extend more than one class.2. A class can extend only one class but many interfaces.3. An interface can extend many interfaces.4. An interface can implement many interfaces.5. A class can extend one class and implement many interfaces.
  1.    1 and 2
  2.    2 and 5
  3.    2 and 4
  4.    3 and 5
  5.    3 and 4
 Discuss Question
Answer: Option D. -> 3 and 5
Question 4. Which is true?
  1.    "X extends Y" is correct if X and Y are either both classes or both interfaces
  2.    "X extends Y" is correct if and only if X is an interface and Y is a class
  3.    "X extends Y" is correct for all combinations of X and Y being classes and/or interfaces
  4.    "X extends Y" is correct if and only if X is a class and Y is an interface
 Discuss Question
Answer: Option A. -> "X extends Y" is correct if X and Y are either both classes or both interfaces
Question 5. The concept of multiple inheritance is implemented in Java byI.   Extending two or more classes.II.  Extending one class and implementing one or more interfaces.III. Implementing two or more interfaces.
  1.    Only (III)
  2.    Only (I)
  3.    (I) and (II)
  4.    Only (II)
  5.    (II) and (III)
 Discuss Question
Answer: Option E. -> (II) and (III)
Question 6. What is the result of compiling and running this program?class Mammal{ void eat(Mammal m){ System.out.println("Mammal eats food"); }}class Cattle extends Mammal{ void eat(Cattle c){ System.out.println("Cattle eats hay"); }}class Horse extends Cattle{ void eat(Horse h){ System.out.println("Horse eats hay"); }}public class Test{ public static void main(String[] args){ Mammal h = new Horse(); Cattle c = new Horse(); c.eat(h); }}
  1.    None of these
  2.    Class cast Exception at runtime.
  3.    prints "Cattle eats hay"
  4.    prints "Horse eats hay"
  5.    prints "Mammal eats food"
 Discuss Question
Answer: Option E. -> prints "Mammal eats food"
Question 7. Determine output:class A{public void method1(){System.out.print("Class A method1");}}class B extends A{public void method2(){System.out.print("Class B method2");}}class C extends B{public void method2(){System.out.print("Class C method2");}public void method3(){System.out.print("Class C method3");}}public class Test{public static void main(String args[]){A a = new A();C c = new C();c.method2();a = c;a.method3();}}
  1.    Compilation Error
  2.    Class B method2 Class C method3
  3.    Runtime exception
  4.    Class C method2 Class C method3
  5.    None of these
 Discuss Question
Answer: Option A. -> Compilation Error
Question 8. What will be the result after compiling this code?class SuperClass{ public int doIt(String str, Integer... data)throws Exception{ String signature = "(String, Integer[])"; System.out.println(str + " " + signature); return 1; }}public class Test extends SuperClass{ public int doIt(String str, Integer... data){ String signature = "(String, Integer[])"; System.out.println("Overridden: " + str + " " +signature); return 0; } public static void main(String... args){ SuperClass sb = new Test(); sb.doIt("hello", 3); }}
  1.    None of these
  2.    Compilation fails
  3.    hello (String, Integer[])
  4.    Overridden: hello (String, Integer[])
 Discuss Question
Answer: Option B. -> Compilation fails
Question 9. What will be the output?class One{ final int a = 15;}class Two extends One{ final int a = 20;}public class Test extends Two{ final int a = 30; public static void main(String args[]){ Test t = new One(); System.out.print(t.a); }}
  1.    Compiler Error
  2.    None of these
  3.    30
  4.    15
  5.    20
 Discuss Question
Answer: Option A. -> Compiler Error
Question 10. What will be the output?class Parent{ public void method(){ System.out.println("Hi i am parent"); }}public class Child extends Parent{ protected void method(){ System.out.println("Hi i am Child"); } public static void main(String args[]){ Child child = new Child(); child.method(); }}
  1.    Compiles successfully and print
  2.    Compiles successfully and print
  3.    Run Time error
  4.    Compile time error
  5.    None of This
 Discuss Question
Answer: Option D. -> Compile time error

Latest Videos

Latest Test Papers