Sunday, 12 March 2023

7. Declare an abstract class Vehicle with an abstract method named numWheels( ).provide subclasses Car and Truck that each implements this method. Create instance of these subclasses and demonstrate the use of this method



abstract class Vehicle
{
    abstract void numwheels();
}

class Car extends Vehicle
{
    void numwheels()
    {
        System.out.println("\nnumber of wheels in car: 4");
    }
}

class Truck extends Vehicle
{
    void numwheels()
    {
        System.out.println("\nnumber of wheels in truck: 6");
    }
}

class Program7
{
    public static void main(String args[])
    {
        Vehicle obj = new Car();
        obj.numwheels();
       
        obj = new Truck();
        obj.numwheels();
    }
}


No comments:

Post a Comment

python programs

1. sum of two number