Friday, February 14, 2020

Java abstract class example

 
Image result for Abstract class in java  using car concept

 Java abstract  class example 

 

abstract class Car
       {
           int regno;
           car(int r)
           {
              regno = r;
           }
         void opentank()
              {
              System.out.println(“fill the tank”);
           }
        

    abstract void steering(int direction, int angle);
     abstract void braking(int force);
       }
      class maruthi extends car
       {
             maruthi(int regno)
             {
                   super(regno);
             }

    void steering(int direction, int angle)
        {
          System.out.println(“take a turn”);
          System.out.println(“this is ordinary   steering”);
        }
        void braking(int force)
       {
        System.out.println(“breaks applied”);

    

    System.out.println(“these are hydraulic    brakes”);
    }
    class santro extends car
         {
           santro(int regno)
           {
                 super(regno);
           }

    void steering(int direction, int angle)
        {
          System.out.println(“take a turn”);
          System.out.println(“this is uses power   steering”);
        }
        void braking(int force)
       {
           System.out.println(“breaks applied”);
           System.out.println(“this car uses gas    brakes”);
        }
    }

No comments:

Post a Comment