0% found this document useful (0 votes)
14 views1 page

1 - Getter Example 1

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)
14 views1 page

1 - Getter Example 1

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/ 1

public class Car3 {

//declare properties
String make;
String model;
int year;
int speed;

//Constructor
public Car3 (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) {


//Create object
Car3 myCar = new Car3("Honda","Civic",2021,180);

// 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