Which of the following is true?
1. A class can extend more than one class.
2. A class can extend only one class but many interfaces.
3. An interface can extend many interfaces.
4. An interface can implement many interfaces.
5. A class can extend one class and implement many interfaces.
A. 1 and 2
B. 2 and 4
C. 3 and 5
D. 3 and 4
E. 2 and 5
Answer: Option C
Join The Discussion
Comments ( 3 )
A. The process of acquiring properties and behaviors of one class by another
B. The process of creating objects
C. The process of encapsulation
D. The process of overloading methods
In Java, which keyword is used to implement inheritance between classes?
A. inheritsFrom
B. inherits
C. implements
D. extends
A. The class that inherits properties and behaviors
B. The child class
C. The class that is inherited from
D. The class that is marked as "final"
In Java, can a subclass inherit constructors from its superclass?
A. Only if the subclass is marked as "final"
B. Yes, a subclass inherits constructors from its superclass
C. Only if the superclass is marked as "static"
D. Only if the subclass is marked as "final"
Here only 2 and 5 are correct.. 3 is not correct because a class can never extend a interface it only implements any number of interfaces. And here 2 is correct because a class can extend only one class but implement many interfaces.
3rd statement is correct because there is no parent class for interface. In case of a class , the super class is object class.
Ex: class A extends Interface1, Interface2, Interface3..... Hence multiple interfaces can be inherited.
can you give simple example of An interface can extend many interfaces?