Abstract Class and Method

//Abstract class
public abstract class CarClass {
    public void carNeedTiers() {
        System.out.println("Car Needs Tiers");
    }

    public void carNeedsEngine() {
        System.out.println("Car Needs Engine");
    }

    public void carNeedsSeats() {
        System.out.println("Car Needs Seats");
    }

    public void carNeedsBody() {
        System.out.println("Car Needs Body");
    }

    //abstract method
    //abstract method should be implemented by inheriting class
    public abstract void carNeedsTrunk();
}

 

 

//Inheriting an abstract class should implement all the abstract methods
public class HondaCar extends CarClass{

    //Overriding
    public void carNeedsEngine() {
        System.out.println("Honda Car Needs Different Engine");
    }

    //abstract method
    public void carNeedsTrunk(){
        System.out.println("Honda Car Trunk Model");
    }


    //new Method
    public void carColor(){
        System.out.println("Honda Car Color");
    }
}

 

//Main Class

 

public class MainClass {

    public static void main(String[] args) {


        //Object CarClass with inherited Class
        CarClass hCarOver = new HondaCar();
        hCarOver.carNeedTiers();

        //Honda Car Object
        HondaCar hondaCar = new HondaCar();
        hondaCar.carNeedTiers();
        hondaCar.carColor();
    }

}

 

 

Print Print | Sitemap
© 2016 Automation Learn. All rights reserved.