scjp 1

Chapter 1

  • Fields of an Object are called instance variables.
  • The values of the instance variables in an object comprise its state.
  • The methods of the object define its behavior. These methods are called instance methods.
  • Instance variables and methods care collectively called instance members. This is to distinguish them from static members, which belong to the class only.
  • A static variable belongs to the class and not to any object of the class. A static variable is initialized when the class is loaded at runtime.
  • Similarly a static method is a method that belong to a class. Static variables and methods comprise the static members.
  • Static members can be accessed via object references, but is considered bad style.
  • There are two fundamental ways of building new classes from existing ones. Inheritance and Aggregation.
class PrintableCharStack extends CharStack {
    //Instance Method
    public void printStackElements() {
        // implementation
    }
 
    public PrintableCharStack(int capacity) {
        super(capacity);
    }    
}
  • A subclass can extend only one super class.
  • When building new classes from existing classes using aggregation, a composite object is built from the constituent objects that are its parts.
  • Since objects cannot contain other objects explicitly, aggregation is by reference only.
Thing item, stuff;
item = new Thing();
Thing entity = new Thing();

In the above example two objects and three reference variables are created by the code. Objects are normally created by using the new operator. The declaration of a reference variable creates a variable regardless of whether a reference value is assigned to it or not.

  • list item

To Do (Further Reading)

  • Reference variable (Object references)
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License