Friday, June 5, 2009

Java Basics Using Qt Jambi Tutorial


Functions are also called methods. Functions are the verb or action for which your program will do.


public class Vehicle{

plublic void accelerate(){


public void turnDirection(){


public static void main(String[] args){

Vehicle car = new Vehicle();




Here, we created the class Vehicle and inside the class are three functions: accelerate,turnDirection and the required main method.

In the main method, we created an instance of a class (can also be called “creating object”) Vehicle with the variable car. The “new” keyword creates the instance and executes the default constructor, then we call the method accelerate like car.accelerate(). This executes the code inside the function we defined accelerate. For our car to turn direction, we call the turnDirection method like this: car.turnDirection();

to be continued...

No comments: