[go: up one dir, main page]

0% found this document useful (0 votes)
3 views3 pages

Solution of Class Program Today

The document is a Java program that defines a class hierarchy for vehicles, including Vehicle, Car, and SportCar classes. It allows user input for vehicle attributes such as brand, year, model, type, and engine capacity, and displays these details. The main method orchestrates the input and output process for a SportCar instance.

Uploaded by

salonisverma77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Solution of Class Program Today

The document is a Java program that defines a class hierarchy for vehicles, including Vehicle, Car, and SportCar classes. It allows user input for vehicle attributes such as brand, year, model, type, and engine capacity, and displays these details. The main method orchestrates the input and output process for a SportCar instance.

Uploaded by

salonisverma77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

package test;

import java.util.*;
class Vehicle
{
String brand;
int year;
void display()
{
System.out.println("Brand: "+brand+" Year: "+year);
}
}
class Car extends Vehicle
{
String model;
void displayCar()
{
System.out.println("Model: "+model);
}
}
class SportCar extends Car
{
String type;
int engine;
void displaySport()
{
System.out.println("Type: "+type+" Engine: "+engine);
}
}
public class Test {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
SportCar s1=new SportCar();
System.out.println("Enter the value of Car brand name and year:");
s1.brand=sc.nextLine();
s1.year=sc.nextInt();
sc.nextLine(); // consume leftover newline
System.out.println("Enter the value of Car model name :");
s1.model=sc.nextLine();
System.out.println("Enter the value of Car engine type and capacity:");
s1.type=sc.nextLine();
s1.engine=sc.nextInt();
s1.display();;
s1.displayCar();
s1.displaySport();
}
}

You might also like