- Abstract class is a class which contain one or more abstract methods, which has to be implemented by sub classes. An abstract class can contain no abstract methods also i.e. abstract class may contain concrete methods.
- Abstract class definition begins with the keyword "abstract" keyword followed by Class definition.
- Abstract classes are useful in a situation when some general methods should be implemented and specialization behavior should be implemented by subclasses.
- Abstract class does not support Multiple Inheritance
- An abstract class can contain private as well as protected members.
- Abstract class need not implement any of the methods defined in the abstract class.
- Any class that contain an abstract method must be declared “abstract” and abstract methods can have definitions only in child classes.
Note:
- There is no difference between a fully abstract class (all methods declared as abstract and all fields are public static final) and an interface.
- Neither Abstract classes nor Interface can be instantiated.
Example:
//@ class level
public
abstract class AbstractClass
//@ Method level
public abstract float
getInfo();
or
public float getInfo(){
............................
...........................
}
Example:
Vehicle is an abstract
class and Bus Truck, car etc are specific implementations

No comments:
Post a Comment