.Tutorial # 4.

Calling a Method
System.out.println(car.whatColour());


The Method
public String whatColour() {
    return this.colour;
}



Variables
Local Variable: A variable that is declared within a method; it exists only during the invocation of the method and is used as a temporary convenient holder of information

Instance Variable: A variable that is declared within a class but outside of any method; its purpose is to store information needed by methods to be preserved in between invocations. Each object has its own set of instance variables that have their own unique values - it is these values that distinguish one object from another. The entire set of the instance variables of an object define its state.


The Mysteries Of Static Revealed

Static Method (aka class method): A method that is not associated with any particular object of a class but rather the class itself. As a result it can be invoked without reference to an object. Static methods are those which exist without instantiating the class, thats why main is static. You can call it without having or refering to an object of that class

Some properties of static:
   static methods cannot access any instance variables.
   static methods do not need to have an object instantitiated to be used.
   A static variable is one that is constant among all instances of that class (ie: you change it in one Student Object, and it has been changed for all of them.)



Sample Classes Demonstrating Program Development Startegy (or Strategy)


mainClass.java - Calls Student.java, to initialize, and use its methods.
Student.java - Models a Student, but only using the most basic constructors, and methods to allow the program to compile.
Student2.java - Models a Student, using completed constructors, variables, and constructors. This would be the second step after your program has already compiled.

books.java - Models a library, feel free to make the book class.
sitemap