Describe invoking methods in java, JAVA Programming

Assignment Help:

Describe Invoking Methods in java?

class Car {

String licensePlate = ""; // e.g. "New York 543 A23"
double speed = 0.0; // in kilometers per hour
double maxSpeed = 123.45; // in kilometers per hour

// accelerate to maximum speed
// put the pedal to the metal
void floorIt() {
this.speed = this.maxSpeed;
}

}
Outside the Car class, you call the floorIt() method just like you reference fields, by using the name of the object you need to accelerate to maximum and the . separator as elaborates below
class CarTest3 {

public static void main(String args[]) {

Car c = new Car();

c.licensePlate = "New York A45 636";
c.maxSpeed = 123.45;

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

c.floorIt();

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

}
}
The output is:
New York A45 636 is moving at 0.0 kilometers per hour.
New York A45 636 is moving at 123.45 kilometers per hour.

The floorIt() method is fully enclosed inside the Car class. Every method in a Java program must belong to a class. Unlike C++ programs, Java programs cannot have techniques hanging around in global space in which does everything you forgot to do inside your classes. 


Related Discussions:- Describe invoking methods in java

Tasks with the classes Currency, In this assignment you work on a set of ta...

In this assignment you work on a set of tasks with the classes Currency, Money and Bank. Money and Currency You have been given a template for the Currency and Money classes (Lab1.

Developed an asteroids game, In the previous assignments, we have developed...

In the previous assignments, we have developed an Asteroids game. In this assignment, we are going to use the same codebase to develop a different gameplay. The inspiration for thi

Who can an applet talk to, Who Can an Applet Talk To? By default an app...

Who Can an Applet Talk To? By default an applet can just open network connections to the system from that the applet was downloaded. This system is known as the codebase. An ap

Action listener and event listener, differende between action listener and ...

differende between action listener and event listener

What is aop(aspect oriented programming)?, Separating your business logic w...

Separating your business logic with other functionality such as services, Loggers etc, making classess more cohesive.

How can you performance tune your database?, 1. De normalizes your tables w...

1. De normalizes your tables where required. 2. Proper use of index columns: An index based on numeric parts is more efficient than an index based on character columns. 3. Re

What is image processing, What is image processing? It field of compute...

What is image processing? It field of computer whereas we enhance and manipulate the graphics. Like it is used to recover old photograph and through processing we can revive

Constructors or destructors in java program, Consider the following Java de...

Consider the following Java definition of an integer list class. class IntegerList { private int[] list = new int[200]; private int size = 0; public boolean append(int value) {

What are checked and unchecked exception, What are Checked and UnChecked Ex...

What are Checked and UnChecked Exception? A checked exception is some subclass of Exception (or Exception itself), excluding class RuntimeException and its subclasses. Making a

Program to find prime number from linked list, For this assignment you are ...

For this assignment you are provided with a class called LNode which can be used as a list node for a linked list of ints. You are also provided with an abstract class called LList

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