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) Which of the following best describes a class in Java?

2 / 50

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

3 / 50

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

4 / 50

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

5 / 50

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

6 / 50

6) Which statement best describes a Java interface?

7 / 50

7) 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();

    }

}

8 / 50

8) 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();

    }

}

9 / 50

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

10 / 50

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

11 / 50

11) What is method overloading in Java?

12 / 50

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

13 / 50

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

14 / 50

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

15 / 50

15) What is abstraction in Java?

16 / 50

16) 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();

    }

}

17 / 50

17) What does the following code demonstrate?

 

class A {

    private int data;

    public void setData(int data) {

        this.data = data;

    }

    public int getData() {

        return data;

    }

}

18 / 50

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

19 / 50

19) What is a static method in Java?

20 / 50

20) 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

    }

}

21 / 50

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

22 / 50

22) 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();

    }

}

23 / 50

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

24 / 50

24) What is an object in Java?

25 / 50

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

26 / 50

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

27 / 50

27) 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();

    }

}

28 / 50

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

29 / 50

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

30 / 50

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

31 / 50

31) 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();

    }

}

32 / 50

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

33 / 50

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

34 / 50

34) 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();

    }

}

35 / 50

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

36 / 50

36) What is polymorphism in Java?

37 / 50

37) What is inheritance in Java?

38 / 50

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

39 / 50

39) What is method overriding in Java?

40 / 50

40) 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();

    }

}

41 / 50

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

42 / 50

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

43 / 50

43) Which of the following correctly demonstrates encapsulation?

44 / 50

44) 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();

    }

}

45 / 50

45) 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);

    }

}

46 / 50

46) 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();

    }

}

47 / 50

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

48 / 50

48) What is an abstract class in Java?

49 / 50

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

50 / 50

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

Your score is

The average score is 64%

thank you for your feedback