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) What is a static method in Java?

2 / 50

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

3 / 50

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

    }

}

4 / 50

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

5 / 50

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

    }

}

6 / 50

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

    }

}

7 / 50

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

8 / 50

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

9 / 50

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

    }

}

10 / 50

10) What is method overloading in Java?

11 / 50

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

    }

}

12 / 50

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

13 / 50

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

    }

}

14 / 50

14) Which statement best describes a Java interface?

15 / 50

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

16 / 50

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

17 / 50

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

    }

}

18 / 50

18) Which of the following correctly demonstrates encapsulation?

19 / 50

19) What is abstraction in Java?

20 / 50

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

    }

}

21 / 50

21) What is an object in Java?

22 / 50

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

23 / 50

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

24 / 50

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

25 / 50

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

26 / 50

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

27 / 50

27) What does the following code demonstrate?

 

class A {

    private int data;

    public void setData(int data) {

        this.data = data;

    }

    public int getData() {

        return data;

    }

}

28 / 50

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

29 / 50

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

    }

}

30 / 50

30) What is polymorphism in Java?

31 / 50

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

    }

}

32 / 50

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

33 / 50

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

34 / 50

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

35 / 50

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

36 / 50

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

37 / 50

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

38 / 50

38) What is method overriding in Java?

39 / 50

39) What is an abstract class in Java?

40 / 50

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

41 / 50

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

42 / 50

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

43 / 50

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

    }

}

44 / 50

44) What is inheritance in Java?

45 / 50

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

46 / 50

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

47 / 50

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

48 / 50

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

    }

}

49 / 50

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

50 / 50

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

Your score is

The average score is 0%

thank you for your feedback