Write the Car setter for variable price and getter method fo

Write the Car setter for variable price and getter method for variable owner. Write code in the main method below to create an object of type Car, set the car to your name, set the number of doors to 5 and print out to the screen the owner of doors and price of car. class Test {public static void main (String[] args) {

Solution

Public class car {

String owner_name;

int number_of_doors;

float price;

}

Public class test {

public static void main (String argv[])

{

car n = new car() ;//creating an object of car

n.owner_name = \"surya\" ;//setting car owner name

n.number_of_doors=5;//setting number of doors of the car

n.price = 360000;//setting car price

//printing output...

System.out.println(\"Car owner name : \"+n.owner_name);

System.out.println(\"no of doors:\" + n.number_of_doors);

System.out.println(\"car price: \" + n.price) ;

}

}

Output:

Car owner name: surya

no of doors: 5

Car price: 360000

 Write the Car setter for variable price and getter method for variable owner. Write code in the main method below to create an object of type Car, set the car

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site