Skip to main content

FEATURED POST

Why the World is Running Out of Computers

Create a base class called “Vehicle” that stores number of wheels and speed.

 Create a base class called “Vehicle” that stores number of wheels and speed. Create the following derived classes:
Ø “Car” that inherits “Vehicle” and also stores number of passengers.
Ø “Truck” that inherits “Vehicle” and also stores the load limit.
Write a main() function to create objects of these classes and display all the information about Car and Truck. Also, compare the speed of the two vehicles, Car and Truck and display “faster” or “slower” if Car is faster or slower than Truck.


import java.util.*;

class Vehicle{

 int wheels;

 double speed;

}

class Car extends Vehicle{

 int pass;

 void input(){

   Scanner sc=new Scanner(System.in);

System.out.println("Enter the car's details:\nNo. of wheels:");

   wheels=sc.nextInt();

System.out.println("Speed of Car(Km/hr):");

   speed=sc.nextDouble();

System.out.println("No. of passengers:");

   pass=sc.nextInt();

}

void display(){

System.out.println("No. of wheels:"+wheels+"\nSpeed:"+speed+"km/hr\nNo. of passengers:"+pass);

    }

}

class Truck extends Vehicle{

 double limit;

 void input()  {

    Scanner sc=new Scanner(System.in);

System.out.println("Enter the Truck's details:\nNo. of wheels:");

    wheels=sc.nextInt();

System.out.println("Speed of Truck(Km/hr):");

    speed=sc.nextDouble();

System.out.println("Load limit:");

    limit=sc.nextDouble();

}

 void display()  {

System.out.println("No. of wheels:"+wheels+"\nSpeed:"+speed+"km/hr\nLoad limit:"+limit);}

    }

class test{

public static void main(String ts7[]){

Car ob1= new Car();

Truck ob2=new Truck();

ob1.input();

ob2.input();

if(ob1.speed>ob2.speed)

System.out.println("Car is faster");

else

System.out.println("Truck is faster");

ob1.display();

ob2.display();

    }

}


Keyword:
How to recover the classnotfoundexception in Java?
What are the top most requirements or expectations of client for develop Java web application?
Java program question paper in 2020
java applet
applet programming in java
creating applet in java

Comments

Popular Posts

Question: Create a base class called “Vehicle” that stores number of wheels and speed. Create the following derived classes

Question: Create a base class called “Vehicle” that stores number of wheels and speed. Create the following derived classes:  Ø “Car” that inherits “Vehicle” and also stores number of passengers.  Ø “Truck” that inherits “Vehicle” and also stores the load limit.  Write a main() function to create objects of these classes and display all the information about Car and Truck. Also, compare the speed of the two vehicles, Car and Truck and display “faster” or “slower” if Car is faster or slower than Truck. import java.util.*; class Vehicle{   int wheels;   double speed; } class Car extends Vehicle{   int pass;   void input(){    Scanner sc=new Scanner(System.in); System.out.println("Enter the car's details:\nNo. of wheels:");    wheels=sc.nextInt(); System.out.println("Speed of Car(Km/hr):");    speed=sc.nextDouble(); System.out.println("No. of passengers:");   ...

Why the World is Running Out of Computers

This April, 19 million new cars were sold in America — the highest level since 2005. But these weren’t just any old cars. Today’s Chevy Silverados and Ram 1500s are not quite the same as those sold a year or even a few months ago. Something very strange is happening a cross the industry.  Features, packages, even certain parts have suddenly disappeared from recently manufactured vehicles. An exceptionally observant buyer of a ‘21Silverado, for example, might notice their truck getting about one less mile per gallon than was advertised earlier this year on the same model. Recent Peugeot 308 hatchback owners, mean while, may be surprised to find the digital speedometer shown on TV replaced with an old-fashioned analog version. And the dashboard display on the Renault Arkana mysteriously got a little bit smaller.  It’s as if they’re playing a game: What tiny things can they change without anyone noticing? The actual explanation is a global shortage of semiconductors — the chips t...

What’s Hiding On Pluto?

What’s Hiding On Pluto? The sun’s gravitational pull stretches out much further than Neptune, all the out to the Kuiper Belt and beyond. To these dark and mysterious satellites, the sun is just a pinprick in the sky. And one of the most mysterious of all is Pluto. Once classified as the ninth planet in the solar system, in 2006 Pluto was downgraded from “planet” to “dwarf planet”. To count as a planet, the International Astronomical Union decided, an object “must have cleared the neighborhood around its orbit”, which Pluto has failed to do due to its relatively small mass. Technically, Pluto is a “trans-Neptunian object” drifting through the Kuiper Belt. It was the discovery of another such object, Eris, that led to the definition of “planet” being changed. Pluto’s surface area is only 3.3% the size of Earth’s - making it about the same size as Russia. On top of being small, Pluto has incredibly low gravity, so little that you’d hardly even notice it – about 6.3% the strength of gravit...