- Which of the following is the base class of all classes in Java?
View Answer
Correct answer: A — Object
- What will be printed?
1 class A { 2 int x = 10; 3 } 4 class B extends A { 5 int x = 20; 6 } 7 public class Test { 8 public static void main(String[] args) { 9 B b = new B(); 10 System.out.println(b.x); 11 } 12 } View Answer
Correct answer: B — 20
- Which of the following is used to achieve runtime polymorphism in Java?
View Answer
Correct answer: B — Method Overriding
- What will be printed?
1 class A { 2 void show() { System.out.println("A"); } 3 } 4 class B extends A { 5 void show() { System.out.println("B"); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 A a = new B(); 10 a.show(); 11 } 12 } View Answer
Correct answer: B — B
- Which of the following is true about constructors in Java?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class A { 2 A() { System.out.println("Constructor A"); } 3 } 4 class B extends A { 5 B() { System.out.println("Constructor B"); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 new B(); 10 } 11 } View Answer
Correct answer: C — Constructor A followed by Constructor B
- Which of the following is used to achieve multiple inheritance in Java?
View Answer
Correct answer: B — Interface
- What will be printed?
1 class A { 2 void display() { System.out.println("A"); } 3 } 4 class B extends A { 5 void display() { System.out.println("B"); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 A a = new A(); 10 a.display(); 11 } 12 } View Answer
Correct answer: A — A
- Which of the following is used to hide implementation details in Java?
View Answer
Correct answer: A — Abstraction
- What will be printed?
1 class A { 2 void show() { System.out.println("Parent"); } 3 } 4 class B extends A { 5 void show() { System.out.println("Child"); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 A obj = new B(); 10 obj.show(); 11 } 12 } View Answer
Correct answer: B — Child
- Which of the following is used to achieve data hiding in Java?
View Answer
Correct answer: A — private variables with getters/setters
- What will be printed?
1 class A { 2 static void show() { System.out.println("Static A"); } 3 } 4 class B extends A { 5 static void show() { System.out.println("Static B"); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 A a = new B(); 10 a.show(); 11 } 12 } View Answer
Correct answer: A — Static A
- Which of the following is true about abstract classes?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 interface A { 2 void show(); 3 } 4 class B implements A { 5 public void show() { System.out.println("Interface implemented"); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 A a = new B(); 10 a.show(); 11 } 12 } View Answer
Correct answer: A — Interface implemented
- Which of the following is true about method overloading?
View Answer
Correct answer: A — Same method name, different parameters
- What will be printed?
1 class A { 2 void show(int x) { System.out.println("int"); } 3 void show(double y) { System.out.println("double"); } 4 } 5 public class Test { 6 public static void main(String[] args) { 7 A a = new A(); 8 a.show(10); 9 } 10 } View Answer
Correct answer: A — int
- Which of the following is true about interfaces in Java?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class A { 2 final void show() { System.out.println("Final method"); } 3 } 4 class B extends A { 5 // void show() { System.out.println("Override"); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 new B().show(); 10 } 11 } View Answer
Correct answer: A — Final method
- Which of the following is true about encapsulation?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class A { 2 void show() { System.out.println("A"); } 3 } 4 class B extends A { 5 void show() { System.out.println("B"); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 B b = new B(); 10 b.show(); 11 } 12 } View Answer
Correct answer: B — B
- What will be printed?
1 class Eduinq { 2 void display() { System.out.println("Eduinq OOP"); } 3 } 4 public class Test { 5 public static void main(String[] args) { 6 Eduinq e = new Eduinq(); 7 e.display(); 8 } 9 } View Answer
Correct answer: A — Eduinq OOP
- Which of the following is true about inheritance in Java?
View Answer
Correct answer: C — Both A and B
- What will be printed?
1 class Eduinq { 2 int id = 101; 3 } 4 public class Test { 5 public static void main(String[] args) { 6 Eduinq e = new Eduinq(); 7 System.out.println(e.id); 8 } 9 } View Answer
Correct answer: A — 101
- Which of the following is true about method overriding?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class Eduinq { 2 void show() { System.out.println("Eduinq Base"); } 3 } 4 class Portal extends Eduinq { 5 void show() { System.out.println("Eduinq Portal"); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 Eduinq e = new Portal(); 10 e.show(); 11 } 12 } View Answer
Correct answer: B — Eduinq Portal
- Which of the following is true about constructors?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class Eduinq { 2 Eduinq() { System.out.println("Eduinq Constructor"); } 3 } 4 public class Test { 5 public static void main(String[] args) { 6 new Eduinq(); 7 } 8 } View Answer
Correct answer: B — Eduinq Constructor
- Which of the following is true about abstract methods?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 abstract class Eduinq { 2 abstract void display(); 3 } 4 class Portal extends Eduinq { 5 void display() { System.out.println("Eduinq Portal Display"); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 Eduinq e = new Portal(); 10 e.display(); 11 } 12 } View Answer
Correct answer: A — Eduinq Portal Display
- Which of the following is true about interfaces?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 interface Eduinq { 2 void show(); 3 } 4 class Portal implements Eduinq { 5 public void show() { System.out.println("Eduinq Interface Implementation"); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 Eduinq e = new Portal(); 10 e.show(); 11 } 12 } View Answer
Correct answer: A — Eduinq Interface Implementation
- Which of the following is true about encapsulation?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class Eduinq { 2 private String name = "Eduinq Private"; 3 public String getName() { return name; } 4 } 5 public class Test { 6 public static void main(String[] args) { 7 Eduinq e = new Eduinq(); 8 System.out.println(e.getName()); 9 } 10 } View Answer
Correct answer: A — Eduinq Private
- Which of the following is true about static methods?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class Eduinq { 2 static void display() { System.out.println("Eduinq Static"); } 3 } 4 public class Test { 5 public static void main(String[] args) { 6 Eduinq.display(); 7 } 8 } View Answer
Correct answer: A — Eduinq Static
- Which of the following is true about final classes?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 final class Eduinq { 2 void show() { System.out.println("Final Eduinq"); } 3 } 4 public class Test { 5 public static void main(String[] args) { 6 Eduinq e = new Eduinq(); 7 e.show(); 8 } 9 } View Answer
Correct answer: A — Final Eduinq
- Which of the following is true about polymorphism?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class Eduinq { 2 void show() { System.out.println("Eduinq Base"); } 3 } 4 class Portal extends Eduinq { 5 void show() { System.out.println("Eduinq Portal"); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 Eduinq e1 = new Eduinq(); 10 Eduinq e2 = new Portal(); 11 e1.show(); 12 e2.show(); 13 } 14 } View Answer
Correct answer: A — Eduinq Base, Eduinq Portal
- Which of the following is true about constructors in inheritance?
View Answer
Correct answer: C — Both A and B
- What will be printed?
1 class Eduinq { 2 Eduinq() { System.out.println("Eduinq Constructor"); } 3 } 4 class Portal extends Eduinq { 5 Portal() { System.out.println("Portal Constructor"); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 new Portal(); 10 } 11 } View Answer
Correct answer: A — Eduinq Constructor, Portal Constructor
- Which of the following is true about super keyword?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class Eduinq { 2 int id = 100; 3 } 4 class Portal extends Eduinq { 5 int id = 200; 6 void show() { System.out.println(super.id); } 7 } 8 public class Test { 9 public static void main(String[] args) { 10 new Portal().show(); 11 } 12 } View Answer
Correct answer: A — 100
- Which of the following is true about overriding rules in Java?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class Eduinq { 2 void show() { System.out.println("Eduinq Base"); } 3 } 4 class Portal extends Eduinq { 5 @Override 6 void show() { System.out.println("Eduinq Portal"); } 7 } 8 public class Test { 9 public static void main(String[] args) { 10 Portal p = new Portal(); 11 p.show(); 12 } 13 } View Answer
Correct answer: B — Eduinq Portal
- Which of the following is true about the this keyword in Java?
View Answer
Correct answer: D — All of the above
- What will be printed?
1 class Eduinq { 2 Eduinq() { System.out.println("Eduinq Constructor"); } 3 Eduinq(String msg) { System.out.println(msg); } 4 } 5 public class Test { 6 public static void main(String[] args) { 7 new Eduinq("Eduinq Overloaded Constructor"); 8 } 9 } View Answer
Correct answer: B — Eduinq Overloaded Constructor
- Which of the following is true about method overloading rules?
View Answer
Correct answer: D — Both A and B
- What will be printed?
1 class Eduinq { 2 void display() { System.out.println("Eduinq Display"); } 3 } 4 class Portal extends Eduinq { 5 void display() { System.out.println("Portal Display"); } 6 } 7 public class Test { 8 public static void main(String[] args) { 9 Eduinq e = new Portal(); 10 e.display(); 11 } 12 } View Answer
Correct answer: B — Portal Display
- Which of the following is true about abstraction and interfaces in Java?
View Answer
Correct answer: D — All of the above