×
FREE ASSISTANCE FOR THE INQUISITIVE PEOPLE
Tutorial Topics
X
softetechnologies
JAVA Practical ISC 2016 Solve - Start and End Vowel
Java Inheritance Examples - Java
4005    Arnab De    15/05/2022

Write a program to create a class named Vehicle having protected instance variables regnNumber, speed, color, ownerName and a method showData() to show "This is a vehicle class". Inherit the Vehicle class into subclasses named Bus and Car having individual private instance variables routeNumber in Bus and manufacturerName in Car and both of them having showData() method showing all details of Bus and Car respectively with content of the super class’s showData ( ) method.

public class Vehicles 
{
    protected String regnNumber, color, ownerName;
    protected int speed;
    MyOwnVehicles(String regno,String c,String owner,int sp)
    {
        regnNumber=regno;
        color=c;
        ownerName=owner;
        speed=sp;
    }
    public void showData() 
	{
        System.out.println("This is a Vehicle Class");
    }
}
softetechnologies
class Bus extends Vehicles 
{
    private int routeNumber;

    Bus(String regno, String c, String owner, int sp, int route) 
	{
        super(regno, c, owner, sp);
        routeNumber = route;
    }

    public void showData() 
	{
        super.showData();
        System.out.println("Reg no: " + regnNumber);
        System.out.println("Color: " + color);
        System.out.println("Owner: " + ownerName);
        System.out.println("Speed: " + speed);
        System.out.println("Route: " + routeNumber);
    }
}
softetechnologies
class Car extends Vehicles
{
    private String manufacturerName;
    Car(String regno, String c, String owner, int sp, String manu) 
	{
        super(regno, c, owner, sp);
        manufacturerName= manu;
    }
    public void showData() 
	{
        super.showData();
        System.out.println("Reg no: " + regnNumber);
        System.out.println("Color: " + color);
        System.out.println("Owner: " + ownerName);
        System.out.println("Speed: " + speed);
        System.out.println("Manufacturer: " + manufacturerName);
    }
}
softetechnologies
import java.util.*;
public class TestVehicle 
{
    public static void main(String[] args) 
	{
        String regno,color,owner,manufacturer;
        int speed,route;

        //Bus
        Scanner sc=new Scanner(System.in);
        System.out.print("Eneter Bus Reg No : ");
        regno=sc.nextLine();
        System.out.print("Eneter Bus color : ");
        color=sc.nextLine();
        System.out.print("Eneter Bus Owner Name : ");
        owner=sc.nextLine();
        System.out.print("Eneter Bus speed : ");
        speed=sc.nextInt();
        System.out.print("Eneter Bus Route No : ");
        route=sc.nextInt();
        Bus b = new Bus(regno,color,owner,speed,route);
        b.showData();

        //Car
        System.out.print("Eneter Car Reg No : ");
        regno=sc.nextLine();
        System.out.print("Eneter Car color : ");
        color=sc.nextLine();
        System.out.print("Eneter Car Owner Name : ");
        owner=sc.nextLine();
        System.out.print("Eneter Car speed : ");
        speed=sc.nextInt();
        System.out.print("Eneter Car Manufacturer : ");
        manufacturer=sc.nextLine();
        Car c = new Car(regno,color,owner,speed,manufacturer);
        c.showData();
    }
}
JAVA Practical ISC 2016 Solve - Start and End Vowel
softetechnologies
Author Details
Arnab De
I have over 16 years of experience working as an IT professional, ranging from teaching at my own institute to being a computer faculty at different leading institute across Kolkata. I also work as a web developer and designer, having worked for renowned companies and brand. Through tutorialathome, I wish to share my years of knowledge with the readers.
Enter New Comment
Comment History
No Comment Found Yet.
Leo Tolstoy
However diffcult life may seem, there is always something you can do, and succeed at. It matters that you don not just give up.
Leo Tolstoy
2625
85.63
Today So Far
Total View (Lakh)
softetechnologies
26/05/2018     54876
25/06/2018     46000
01/01/2018     44158
28/06/2017     41723
02/08/2017     40805
01/08/2017     34813
06/07/2017     34575
15/05/2017     33786
11/09/2018     31452
14/07/2017     30672
softetechnologies