Can we write abstract class without method If yes what is use

Can we write abstract class without method If yes what is use

Answer: Yes. An empty abstract class is very much equivalent to an interface except that it can extend a class:

package com.javahonk;

abstract class AbstractClass // extends anotherClass implements anInterface
{

}

interface TestInterface // extends anotherInterface
{

}

 

This pattern is called Marker interface.

If you answer sometimes we need a base class for implement polymorphism then interviewer will ask you an interface won’t do. My answer would be:
Yes, main difference is that you can implement some code in your base class, or define some attributes.

Leave a Reply

Your email address will not be published. Required fields are marked *

I am not Robot *