Java OOPs Concepts Test 1

    Question 1JAVA OOPS - Class and Object Creation

    Which of the following correctly creates an object of class Car?

    class Car {}

    Question 2JAVA OOPS - Default Constructor

    What does Java provide if no constructor is defined in a class?

    class Person {}

    Question 3JAVA OOPS - Single Inheritance

    Which of the following is true about single inheritance in Java?

    Question 4JAVA OOPS - Compile-time Polymorphism

    Which of the following demonstrates compile-time polymorphism in Java?

    class Demo { void show() { System.out.println("No-arg"); } void show(int x) { System.out.println(x); } }

    Question 5JAVA OOPS - Abstract Class Basics

    Which of the following statements about abstract classes is true?

    Question 6JAVA OOPS - Encapsulation Basics

    Which of the following statements is true about encapsulation?

    Question 7JAVA OOPS - Interface Basics

    Which of the following is true about interfaces in Java?

    Question 8JAVA OOPS - Package Basics

    Which of the following is true about packages in Java?

    Question 9JAVA OOPS - Final Variable Basics

    Which of the following is true about a final variable in Java?

    Question 10JAVA OOPS - Object Class Basics

    Which of the following is true about the Object class in Java?

    Question 11JAVA OOPS - Accessing Object Members

    What will be the output of the following code?

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

    Question 12JAVA OOPS - Parameterized Constructor

    Which statement correctly creates a parameterized constructor object?

    class Car { String model; Car(String m) { model = m; } }

    Question 13JAVA OOPS - Multilevel Inheritance

    What will be printed?

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

    Question 14JAVA OOPS - Method Overloading Example

    What will be printed?

    class Demo { int add(int a, int b) { return a + b; } double add(double a, double b) { return a + b; } } public class Main { public static void main(String[] args) { Demo d = new Demo(); System.out.println(d.add(5, 5)); System.out.println(d.add(5.0, 5.0)); } }

    Question 15JAVA OOPS - Abstract Method Implementation

    What will happen when we run the following code?

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

    Question 16JAVA OOPS - Encapsulation Example

    What will be printed?

    class Person { private String name; public void setName(String n) { name = n; } public String getName() { return name; } } public class Main { public static void main(String[] args) { Person p = new Person(); p.setName("Alice"); System.out.println(p.getName()); } }

    Question 17JAVA OOPS - Implementing Interface

    What will be printed?

    interface A { void show(); } class B implements A { public void show() { System.out.println("Hello"); } } public class Main { public static void main(String[] args) { A obj = new B(); obj.show(); } }

    Question 18JAVA OOPS - Default Package

    Which statement is correct?

    Question 19JAVA OOPS - Final Variable Example

    What will happen?

    class Demo { final int x = 10; void change() { // x = 20; // Uncommenting this line } }

    Question 20JAVA OOPS - Object Class Methods

    Which of the following methods are defined in Object class?