Difference between abstract class and interfaceAbstract class and interface both are used to achieve abstraction where we can declare the abstract methods. Abstract class and interface both can't be instantiated. But there are many differences between abstract class and interface that are given below.
Simply, abstract class achieves partial abstraction (0 to 100%) whereas interface achieves fully abstraction (100%). Example of abstract class and interface in JavaLet's see a simple example where we are using interface and abstract class both. Test it NowOutput: I am a I am b I am c I am d Abstract class vs Interface MCQ1. Which of the following can an abstract class have that an interface cannot?
Answer: D) Explanation: An abstract class can have a constructor, whereas an interface cannot. 2. How many interfaces can a class implement in Java?
Answer: C) Explanation: A class in Java can implement multiple interfaces. 3. Which feature is exclusive to interfaces and not available in abstract classes?
Answer: C) Explanation: Interfaces in Java 8 and later can have default methods, which provide method implementations, unlike abstract classes that cannot have default methods. 4. Can an abstract class be instantiated directly?
Answer: B) Explanation: An abstract class cannot be instantiated directly; it requires a subclass to provide implementations for its abstract methods. 5. Which of the following is true about abstract classes but not interfaces in Java?
Answer: B) Explanation: Abstract classes can extend other classes, whereas interfaces cannot. Next TopicPackage in Java |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India