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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy