Which two of the following are legal declarations for abstract classes and interfaces?
1. final abstract class Test {}
2. public static interface Test {}
3. final public class Test {}
4. protected abstract class Test {}
5. protected interface Test {}
6. abstract public class Test {}
A. 1 and 2
B. 2 and 4
C. 3 and 5
D. 5 and 6
E. 3 and 6
Answer: Option E
Solution(By Examveda Team)
(3), (6). Both are legal class declarations.
(1) is wrong because a class cannot be abstract and final "there would be no way to use such a class". (2) is wrong because interfaces and classes cannot be marked as static. (4) and (5) are wrong because classes and interfaces cannot be marked as protected.
Join The Discussion
Comments ( 1 )
A. A contract specifying a set of methods that a class must implement
B. A class that cannot be instantiated
C. A class that contains only static methods
D. A subclass of the Object class
In Java, can a class implement multiple interfaces?
A. Interfaces cannot be implemented by classes
B. Only abstract classes can implement interfaces
C. No, a class can only implement one interface
D. Yes, a class can implement multiple interfaces
What is the purpose of an abstract class in Java?
A. To declare abstract methods
B. To provide a base class with common methods and fields
C. To make a class final
D. To declare abstract methods
There is no abstract key in statement 3.The statement is true but its not about abstract class or interface.