Java OOPs Concepts Test 3

    Question 1JAVA OOPS - Object Creation Syntax

    Which statement is invalid?

    class Car {}

    Question 2JAVA OOPS - `this()` Keyword in Constructor

    What will the following code print?

    class Test { Test() { System.out.println("Default"); } Test(int x) { this(); System.out.println(x); } } public class Main { public static void main(String[] args) { Test t = new Test(5); } }

    Question 3JAVA OOPS - super Keyword

    Which statement is true about super keyword?

    Question 4JAVA OOPS - `super` in Runtime Polymorphism

    What will be printed?

    class A { void show() { System.out.println("Parent"); } } class B extends A { void show() { super.show(); System.out.println("Child"); } } public class Main { public static void main(String[] args) { B obj = new B(); obj.show(); } }

    Question 5JAVA OOPS - Interface vs Abstract Class

    Which is true about interface and abstract class?

    Question 6JAVA OOPS - Write-only Property

    Which statement is correct?

    Question 7JAVA OOPS - Interface Reference

    Which statement is correct?

    interface A { void show(); } class B implements A { public void show() { System.out.println("Hi"); } }

    Question 8JAVA OOPS - Accessing Classes in Package

    Which statement about access modifiers is correct for packages?

    Question 9JAVA OOPS - Final Class

    Which statement is true about a final class?

    Question 10JAVA OOPS - toString() Overriding

    What is the purpose of overriding toString() method?

    Question 11JAVA OOPS - Class Member Access

    What will be the output?

    class A { int x = 10; } class B { int y = 20; } public class Main { public static void main(String[] args) { A a = new A(); B b = new B(); System.out.println(a.x + b.y); } }

    Question 12JAVA OOPS - Constructor Chaining

    Which concept is demonstrated here?

    class Demo { Demo() { System.out.println("A"); } Demo(int x) { this(); System.out.println("B"); } }

    Question 13JAVA OOPS - Multiple Inheritance

    Why is multiple inheritance not allowed with classes in Java?

    Question 14JAVA OOPS - Polymorphism with Return Type

    Which is true about overriding and return types?

    Question 15JAVA OOPS - Abstract Class Reference

    What will be printed?

    abstract class A { abstract void show(); void display() { System.out.println("Display"); } } class B extends A { void show() { System.out.println("Show"); } } public class Main { public static void main(String[] args) { A obj = new B(); obj.display(); } }

    Question 16JAVA OOPS - Multiple Objects Encapsulation

    What will be printed?

    class Counter { private int count = 0; public void increment() { count++; } public int getCount() { return count; } } public class Main { public static void main(String[] args) { Counter c1 = new Counter(); Counter c2 = new Counter(); c1.increment(); System.out.println(c2.getCount()); } }

    Question 17JAVA OOPS - Interface with Variables

    Which of the following statements is true?

    Question 18JAVA OOPS - Sub-package Access

    Which statement is correct?

    Question 19JAVA OOPS - Final Class Example

    Which of the following will cause an error?

    final class A {} class B extends A {}

    Question 20JAVA OOPS - equals() Overriding

    Which statement is correct about equals() method?