Looking For Anything Specific?

ads header

Abstract modifier in java

Abstract

 

The abstract is a modifier, applicable for classes, and methods but not for variables,


Even though we don't know about the implementation .we can declare a method with an abstract modifier.

In the abstract method, the only declarations are available but not for implementations.

Hence abstract method declaration should end with a semicolon (;)  


example

public abstract void m1();


The child class is responsible for the implementation of parent class abstract methods. 


abstract class Vehicle  

{

    abstract public int getNoWheels();

}



class Bus extends  Vehicle                                        

{

    abstract public int getNoWheels()

    {

        return 7;

    }

}



class Car  extends  Vehicle

{

    abstract public int getNoWheels()

    {

        return 4;

    }

}      


So 

By declaring an abstract method in the parent class we can provide guidelines ti child class such that which method compulsory child has to implement.


the abstract method never talks about implementation.

Post a Comment

0 Comments