Give an example for using getter methods, JAVA Programming

Assignment Help:

Give an example for Using Getter Methods ?

class CarTest6 {

public static void main(String args[]) {

Car c = new Car();

c.setLicensePlate("New York A45 636");
c.setMaximumSpeed(123.45);

System.out.println(c.getLicensePlate() + " is moving at "
+ c.getSpeed() + " kilometers per hour.");

for (int i = 0; i < 15; i++) {
c.accelerate(10.0);
System.out.println(c.getLicensePlate() + " is moving at "
+ c.getSpeed() + " kilometers per hour.");
}

}

}
There's no longer any direct access to fields!

Here's the output:
utopia% java CarTest6
New York A45 636 is moving at 0.0 kilometers per hour.
New York A45 636 is moving at 10.0 kilometers per hour.
New York A45 636 is moving at 20.0 kilometers per hour.
New York A45 636 is moving at 30.0 kilometers per hour.
New York A45 636 is moving at 40.0 kilometers per hour.
New York A45 636 is moving at 50.0 kilometers per hour.
New York A45 636 is moving at 60.0 kilometers per hour.
New York A45 636 is moving at 70.0 kilometers per hour.
New York A45 636 is moving at 80.0 kilometers per hour.
New York A45 636 is moving at 90.0 kilometers per hour.
New York A45 636 is moving at 100.0 kilometers per hour.
New York A45 636 is moving at 110.0 kilometers per hour.
New York A45 636 is moving at 120.0 kilometers per hour.
New York A45 636 is moving at 123.45 kilometers per hour.
New York A45 636 is moving at 123.45 kilometers per hour.
New York A45 636 is moving at 123.45 kilometers per hour.


Related Discussions:- Give an example for using getter methods

Explain the three benefits of access protection, Explain the Three Benefits...

Explain the Three Benefits of Access Protection ? Access protection has three major benefits: 1. It permits you to enforce constraints on an object's state. 2. It gives a si

Type of messaging is given by jms, Point-to-Point : gives a traditional qu...

Point-to-Point : gives a traditional queue based mechanism where the client application forwards a message through a queue to typically one receiving client that accepts messages

Explain the ? operator in java, Explain The ?  operator in Java ? The...

Explain The ?  operator in Java ? The value of a variable frequent depends on whether a particular boolean expression is or is not true and on nothing else. For example one ge

Create a wall posting class, Your FaceBooklet application will use the clas...

Your FaceBooklet application will use the classes you wrote for Program 3. Start by creating a copy of your Program 3 project with a new name (say, "Program4"). Note that you ca

What are the steps of working of tcp and ip protocols, What are the steps o...

What are the steps of working of TCP and IP protocols within internet transmission? TCP divide messages in several packets (capsulation) and sent these messages over the internet

Explain data entry issues, Explain data entry issues? DATA ENTRY: The...

Explain data entry issues? DATA ENTRY: There is new data entered every day. New customers are added every day. Some of the data entry needs the manual entry within computer s

Java identifiers, 1. Which of the following are not valid Java identifiers,...

1. Which of the following are not valid Java identifiers, and why? (a) wolVes (b) United(there is only one) (c) 87 (d) 5 3 (e) Real ale (f) isFound?by 2. A cla

Differentiation between a vector and an array, Differentiation between a V...

Differentiation between a Vector and an array . Explain in Brief about the pros and cons of both?

I want android application with motion detection, I want Android applicatio...

I want Android application with motion detection Project Description: We need to develop a simple application for android which uses motion detection libraries from open sour

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd