Java OOP Essentials for Backend Development Quiz

Explore core Java object-oriented concepts essential for backend development, with questions covering classes, inheritance, encapsulation, and polymorphism.

  1. Class and Object Basics

    Which keyword is used in Java to create a new object from a class?

    1. make
    2. create
    3. instance
    4. new

    Explanation: The 'new' keyword is required in Java to instantiate a new object from a class. 'create' and 'make' are not valid Java keywords, while 'instance' relates to the idea but is not the keyword used for object creation.

  2. Understanding Inheritance

    What keyword allows a class in Java to inherit properties and methods from another class?

    1. extends
    2. inherits
    3. inheritsfrom
    4. implements

    Explanation: 'extends' enables a class to inherit from a superclass. 'implements' is for interfaces, and 'inherits'/'inheritsfrom' are not valid Java keywords, making 'extends' the only correct choice.

  3. Encapsulation Features

    Which access modifier restricts member variables to be accessed only within the class itself in Java?

    1. protected
    2. public
    3. default
    4. private

    Explanation: 'private' restricts access strictly to the same class, ensuring encapsulation. 'protected' allows subclass and package access, 'public' allows access everywhere, and 'default' gives package-level access, none of which fully encapsulate the field.

  4. Polymorphism in Practice

    What is runtime polymorphism in Java typically achieved through?

    1. Method overloading
    2. Method overriding
    3. Constructor chaining
    4. Variable shadowing

    Explanation: Runtime polymorphism is mainly achieved by method overriding, where a subclass provides a specific implementation of a superclass method. Method overloading involves compile-time polymorphism, while variable shadowing and constructor chaining do not relate to runtime polymorphism.