Exercises

Object-Oriented Programming in Java

Challenge your understanding of object-oriented programming in Java. This quiz covers core OOP concepts including inheritance with extends, encapsulation, interfaces and polymorphism, constructors, method overloading, abstract classes, protected access, and the super keyword. You will also test your knowledge of static versus instance methods and predict the output of a simple Java class. Whether you are learning Java fundamentals or reviewing for an exam or interview, these questions will help you assess your grasp of essential Java OOP principles.

Answer the questions below and check the explanation for each answer.

0/10 answered

  1. 1

    What does the 'extends' keyword signify in Java?

  2. 2

    Which is a valid declaration of a constructor for a class named 'Car'?

  3. 3

    What is Encapsulation in Java?

  4. 4

    What is the output of the following code snippet?

    public class Test {
    private String name = "John";
    public String getName() {
    return name;
    }
    public static void main(String[] args) {
    Test test = new Test();
    System.out.println(test.getName());
    }
    }

  5. 5

    How is a static method different from a non-static method?

  6. 6

    Which principle of Object-Oriented Programming does the following code demonstrate?

    interface Drawable {
    void draw();
    }
    class Circle implements Drawable {
    public void draw() {
    // Draw Circle
    }
    }

  7. 7

    If a method is marked as 'protected', where can it be accessed?

  8. 8

    What is the purpose of the 'super' keyword in Java?

  9. 9

    Which of the following is an example of method overloading?

  10. 10

    What happens when an 'abstract' class is instantiated in Java?

Download the App now to have access to + 5000 free courses, exercises, certificates and lots of content without paying anything!

  • 100% free online courses from start to finish

    Thousands of online courses in video, ebooks and audiobooks.

  • More than 60 thousand free exercises

    To test your knowledge during online courses

  • Valid free Digital Certificate with QR Code

    Generated directly from your cell phone's photo gallery and sent to your email

Cursa app on the ebook screen, the video course screen and the course exercises screen, plus the course completion certificate