← Back to Home

Java OOP Concepts

10 questions · Classes, Inheritance, Polymorphism & more

Encapsulation Inheritance Polymorphism Abstraction Interfaces
Q 01 / 10 Classes & Objects

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

new is the keyword used to instantiate objects in Java. For example: Dog d = new Dog(); allocates memory and calls the constructor. There is no create or object keyword in Java.
Q 02 / 10 Encapsulation

What is the main purpose of encapsulation in OOP?

Encapsulation bundles data (fields) and the methods that operate on that data into a single unit (class), while hiding the internal state from outside access. It is achieved using private fields with public getters/setters.
Q 03 / 10 Inheritance

What will the following code output?

class Animal { void sound() { System.out.println("Generic sound"); } } class Dog extends Animal { void sound() { System.out.println("Woof"); } } public class Main { public static void main(String[] args) { Animal a = new Dog(); a.sound(); } }
Woof — This demonstrates runtime polymorphism (dynamic dispatch). Even though the reference type is Animal, the actual object is Dog, so the overridden sound() in Dog is called at runtime.
Q 04 / 10 Abstraction

Which of the following is true about abstract classes in Java?

Abstract classes can have both abstract and non-abstract methods. They cannot be instantiated directly. A subclass must implement all abstract methods (or itself be declared abstract). Java supports only single class inheritance, so a class can extend only one abstract class.
Q 05 / 10 Interfaces

Which keyword does a class use to implement an interface in Java?

implements is used by a class to adopt an interface contract. A class uses extends for another class and implements for interfaces. A class can implement multiple interfaces: class Foo implements A, B { }.
Q 06 / 10 Polymorphism

Method overloading in Java is an example of which type of polymorphism?

Compile-time polymorphism (also called static binding). Method overloading is resolved at compile time based on the method signature (number/type of parameters). Method overriding is runtime polymorphism — resolved at runtime via dynamic dispatch.
Q 07 / 10 Inheritance

What does the super keyword do in Java?

super refers to the immediate parent class. It can be used to call the parent constructor (super()) or a parent method (super.method()). This is useful when you override a method but still want to invoke the parent's version.
Q 08 / 10 Interfaces vs Abstract

Which statement correctly differentiates an interface from an abstract class in Java?

A class can implement multiple interfaces but extend only one abstract class. This is Java's solution to the diamond problem. Since Java 8, interfaces can also have default and static methods. Interfaces use public static final constants, not regular instance variables.
Q 09 / 10 Constructors

What is a constructor in Java?

A constructor is a special method that has the same name as the class and no return type (not even void). It is automatically called when an object is created with new. Java provides a default no-arg constructor if none is defined.
Q 10 / 10 final keyword

Which of the following correctly describes the effect of the final keyword on a class?

A final class cannot be subclassed. For example, the String class in Java is final — you cannot extend it. Similarly, final on a method prevents overriding, and final on a variable makes it a constant.

Quiz Complete! 🎓

0%

You answered 0 out of 10 correctly.

0
Correct
0
Wrong
⌂ Back to Home