Classes and Objects
- 100% developed as of Nov 9, 2012 Defining classes
- 100% developed as of Dec 5, 2013 Inheritance
- 100% developed as of Dec 5, 2013 Interfaces
- 75% developed as of Jun 4, 2013 Overloading methods and constructors
- 75% developed as of Nov 20, 2013 Object Lifecycle
- 100% developed as of Nov 20, 2013 Scope
- 75% developed as of Oct 27, 2006 Nested classes
- 100% developed as of Dec 5, 2013 Generics
Classes and Objects
[edit | edit source ]An object-oriented program is built from objects. A class is a "template" that is used to create objects. The class defines the values the object can contain and the operations that can be performed on the object.
After compilation, a class is stored on the file system in a '(class-name).class' file.
The class is loaded into memory when we are about to create the first object from that class, or when we call one of its static functions.
During class loading all the class static variables are initialized. Also operations defined in a static { ... }
block are executed. Once a class is loaded it stays in memory, and the class static variables won't be initialized again.
After the class is loaded into memory, objects can be created from that class. When an object is created, its member variables are initialized, but the class static variables are not.
When there are no more references to an object, the garbage collector will destroy the object and free its memory, so that the memory can be reused to hold new objects.