0% found this document useful (0 votes)
20 views2 pages

2 - Getter Example 2

Uploaded by

Juan Dela Cruz
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)
20 views2 pages

2 - Getter Example 2

Uploaded by

Juan Dela Cruz
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/ 2

public class Car2 {

//decalre properties of objects


String make;
String model;
int year;
int speed;

//constructor for the class


public Car2 (String make, String model, int year, int speed){
this.make = make;
this.model = model;
this.year = year;
this.speed = speed;
}

//Getter method for properties


public String getMake(){
return make;
}

public String getModel(){


return model;
}

public int getYear(){


return year;
}

public int getSpeed(){


return speed;
}

public static void main(String[] args) {


Scanner scanner = new Scanner(System.in);

System.out.print("Enter make ");


String make = scanner.nextLine();

System.out.print("Enter model ");


String model = scanner.nextLine();

System.out.print("Year ");
int year = scanner.nextInt();

System.out.print("Speed ");
int speed = scanner.nextInt();
//Create a car

Car2 myCar= new Car2(make, model, year, speed);

// Get and print the properties of the car object


System.out.println("Make "+ myCar.getMake());
System.out.println("Model "+ myCar.getModel());
System.out.println("Year "+ myCar.getYear());
System.out.println("Speed "+ myCar.getSpeed());

}
}

You might also like