NEW
Font size
WorksheetsInheritance and Interfaces in Java
Total questions: 10
Worksheet time: 5mins
What is the primary difference between a class and an interface in Java?
A class can implement methods and hold state, while an interface only declares methods without implementations.
Both classes and interfaces can implement methods, but only classes can be instantiated.
A class can only declare methods without implementations, while an interface can hold state.
An interface can hold state, while a class only declares methods without implementations.
Can a class implement multiple interfaces in Java?
A class can only implement one interface in Java.
Interfaces cannot be implemented by classes in Java.
A class can extend multiple classes in Java.
Yes, a class can implement multiple interfaces in Java.
What is an abstract class in Java?
An abstract class in Java is a class that cannot be instantiated and may contain abstract methods that must be implemented by subclasses.
An abstract class is a class that has no fields.
An abstract class cannot contain any methods.
An abstract class can be instantiated directly.
How does multiple inheritance work in Java?
Java supports multiple inheritance through interfaces, not classes.
Java supports multiple inheritance via abstract classes.
Java allows multiple inheritance through classes.
Java uses a mixin approach for multiple inheritance.
How does polymorphism work with interfaces in Java?
Interfaces cannot be used for method overriding in Java.
Polymorphism allows only one class to implement an interface at a time.
Polymorphism with interfaces in Java allows different classes to implement the same interface and be treated as instances of that interface, enabling method overriding and dynamic method resolution.
Polymorphism with interfaces requires static method resolution.
Can an interface extend another interface?
An interface can only implement another interface.
An interface can extend a class but not another interface.
Yes, an interface can extend another interface.
No, an interface cannot extend another interface.
What happens if a class implements an interface but does not provide implementations for all its methods?
The class will compile without errors.
The class must be declared abstract.
The class can be instantiated without any issues.
The class will automatically implement the missing methods.
What is the difference between an abstract class and an interface?
An abstract class cannot have any methods.
An abstract class is always public, while an interface is always private.
An abstract class can have implemented methods and state, while an interface cannot.
An interface can have state and implemented methods.
What is the role of the 'implements' keyword in Java?
The 'implements' keyword allows a class to implement an interface in Java.
The 'implements' keyword is used to declare a variable in Java.
The 'implements' keyword is used to define a class in Java.
The 'implements' keyword allows a class to extend another class in Java.
How does Java handle method resolution in case of multiple inheritance?
Java handles method resolution in multiple inheritance through interfaces by requiring explicit method overriding in case of conflicts.
Java allows multiple inheritance directly through classes without any restrictions.
Java uses a priority system based on class hierarchy to resolve method conflicts.
Java automatically resolves method conflicts by choosing the most recently defined method.
