Friday, September 11, 2020

Abstract Class in Java

              Abstract Class in Java

Abstarct CLASS:

Definition: A class which is declared with the abstract keyword is known as an abstract class in Java. It can have abstract and non-abstract methods (method with the body).

i)A class with partial implementation.
ii)NO one can create a object.
iii)No one can call its methods.
iv)Event though class do not contain abstract method we can declare class as abstract
v)It can contain abstract and non abstract method also

***Every child class must provide abstract method implementation.



Example;
public abstarct class vechicle
{

public abstract int Noof whlees();

}

class bus extends vechicle{
public int noof wheels(){
return 6;
}
}

class car extends vechicle{
public int noof wheels(){
return 4;
}
}

class test{
bus b =new bus();
b.noof wheels();
car c= new car();
c.noof  wheels();
}
}

OutPut:
6
4







7 comments: