Java 50: OOP Quiz Challenge

  • Post category:Java Quiz
  • Reading time:1 mins read

Welcome to our Java OOP Quiz!

We have 50 multiple-choice Java questions for you to test your Object-Oriented Programming (OOP) knowledge.

Give it a try and see how well you understand Java OOP concepts.

Java OOP Concepts Quiz

Ready to test your Java skills? This quiz will help you check how well you know the basics of Object-Oriented Programming (OOP) in Java. It’s perfect for beginners and anyone who wants to review the key concepts of OOP.

1 / 50

1) Consider the following code snippet. What will be the output?

 

 

abstract class Shape {

    abstract void draw();

}

class Circle extends Shape {

    void draw() {

        System.out.println(“Drawing Circle”);

    }

}

public class Test {

    public static void main(String[] args) {

        Shape s = new Circle();

        s.draw();

    }

}

2 / 50

2) Consider the following class definitions. What will be the output of the `main` method?

 

 

class Parent {

    void display() {

        System.out.println(“Parent display”);

    }

}

class Child extends Parent {

    void display() {

        System.out.println(“Child display”);

    }

}

public class Test {

    public static void main(String[] args) {

        Parent obj = new Child();

        obj.display();

    }

}

3 / 50

3) Which of the following is an example of encapsulation?

4 / 50

4) What will be the result of the following code?

 

interface Vehicle {

    void start();

}

class Car implements Vehicle {

    public void start() {

        System.out.println(“Car starting”);

    }

}

public class Test {

    public static void main(String[] args) {

        Vehicle v = new Car();

        v.start();

    }

}

5 / 50

5) What is the purpose of the `transient` keyword in Java?

6 / 50

6) What is polymorphism in Java?

7 / 50

7) What is the effect of marking a class as `abstract` in Java?

8 / 50

8) What is inheritance in Java?

9 / 50

9) What will be the result of the following code?

 

class Base {

    public void display() {

        System.out.println(“Base display”);

    }

}

class Derived extends Base {

    public void display() {

        super.display();

        System.out.println(“Derived display”);

    }

}

public class Test {

    public static void main(String[] args) {

        Derived obj = new Derived();

        obj.display();

    }

}

10 / 50

10) What is method overriding in Java?

11 / 50

11) What is the purpose of the `native` keyword in Java?

12 / 50

12) What is the purpose of the `super` keyword in Java?

13 / 50

13) Which keyword is used to inherit a class in Java?

14 / 50

14) What is abstraction in Java?

15 / 50

15) Which of the following best describes an enum in Java?

16 / 50

16) Which of the following statements is true about constructors in Java?

17 / 50

17) What will be the output of the following code?

 

class Animal {

    void sound() {

        System.out.println(“Animal makes a sound”);

    }

}

class Cat extends Animal {

    void sound() {

        System.out.println(“Cat meows”);

    }

}

public class Test {

    public static void main(String[] args) {

        Animal a = new Cat();

        a.sound();

    }

}

18 / 50

18) Which of the following best describes a class in Java?

19 / 50

19) What is the purpose of the `protected` access modifier in Java?

20 / 50

20) What does it mean if a method is synchronized in Java?

21 / 50

21) What is an object in Java?

22 / 50

22) Which access modifier in Java allows members to be accessible only within the same class?

23 / 50

23) What is the purpose of the `this` keyword in Java?

24 / 50

24) Which of the following statements is true about the `super` keyword in Java?

25 / 50

25) Which of the following statements is true about nested classes in Java?

26 / 50

26) What will be the result of the following code?

 

interface A {

    int VALUE = 5;

    void display();

}

class B implements A {

    public void display() {

        System.out.println(“B display”);

    }

}

public class Test {

    public static void main(String[] args) {

        A obj = new B();

        obj.display();

        System.out.println(A.VALUE);

    }

}

27 / 50

27) What is a static method in Java?

28 / 50

28) What does it mean if a class is marked as `abstract` in Java?

29 / 50

29) Which of the following is true about a final class in Java?

30 / 50

30) What is an abstract class in Java?

31 / 50

31) What is the difference between an interface and an abstract class in Java?

32 / 50

32) Which of the following is true about the `instanceof` keyword in Java?

33 / 50

33) What does the following code demonstrate?

 

class A {

    private int data;

    public void setData(int data) {

        this.data = data;

    }

    public int getData() {

        return data;

    }

}

34 / 50

34) What is the difference between method overloading and method overriding in Java?

35 / 50

35) What will be the output of the following code?

 

class Parent {

    static void show() {

        System.out.println(“Parent show”);

    }

}

class Child extends Parent {

    static void show() {

        System.out.println(“Child show”);

    }

}

public class Test {

    public static void main(String[] args) {

        Parent obj = new Child();

        obj.show();

    }

}

36 / 50

36) What does the `static` keyword indicate when applied to a class member in Java?

37 / 50

37) Which statement best describes a Java interface?

38 / 50

38) What is the result of the following code?

 

interface Printable {

    void print();

}

class Document implements Printable {

    public void print() {

        System.out.println(“Printing Document”);

    }

}

public class Test {

    public static void main(String[] args) {

        Printable p = new Document();

        p.print();

    }

}

39 / 50

39) What will be the result of the following code?

 

 

class X {

    public void methodX() {

        System.out.println(“Method in class X”);

    }

}

class Y extends X {

    public void methodY() {

        System.out.println(“Method in class Y”);

    }

}

public class Test {

    public static void main(String[] args) {

        X obj = new Y();

        obj.methodX();

        // obj.methodY(); // This line is commented out

    }

}

40 / 50

40) Which of the following correctly demonstrates encapsulation?

41 / 50

41) What is the output of the following code?

 

 

class Animal {

    public void makeSound() {

        System.out.println(“Animal sound”);

    }

}

class Dog extends Animal {

    public void makeSound() {

        System.out.println(“Bark”);

    }

}

public class Test {

    public static void main(String[] args) {

        Animal a = new Dog();

        a.makeSound();

    }

}

42 / 50

42) What is method overloading in Java?

43 / 50

43) What is the purpose of the `final` keyword when applied to a method in Java?

44 / 50

44) Which of the following is true about the `default` keyword in an interface in Java?

45 / 50

45) Which of the following statements is true about interfaces in Java?

46 / 50

46) Which keyword is used to prevent a class from being subclassed in Java?

47 / 50

47) Consider the following code. What will be the output?

 

 

class A {

    static void print() {

        System.out.println(“A”);

    }

}

class B extends A {

    static void print() {

        System.out.println(“B”);

    }

}

public class Test {

    public static void main(String[] args) {

        A obj = new B();

        obj.print();

    }

}

48 / 50

48) What will be the result of the following code?

 

class A {

    final void display() {

        System.out.println(“A display”);

    }

}

class B extends A {

    // void display() {

    //     System.out.println(“B display”);

    // }

}

public class Test {

    public static void main(String[] args) {

        B obj = new B();

        obj.display();

    }

}

49 / 50

49) Which of the following statements is true about the `default` keyword in Java interfaces?

50 / 50

50) What is the purpose of the `super` keyword when used in a constructor?

Your score is

The average score is 0%

thank you for your feedback