A variable of a class type holds a reference to an object of that class.
- Non-static nested classes (inner classes) are members of their enclosing class and have access to other members of the enclosing class, while static nested classes are not members of their enclosing class and do not have access to the instance variables and methods of the enclosing class.
- Non-static nested classes can access non-static members of the enclosing class directly, while nested static classes cannot and need to create an instance of the enclosing class to access them
To construct an object, you use the
new operator, followed by a call to the constructor.
new operator returns the constructed object, or, more precisely, a reference to that object—we will discuss that distinction in detail in the section on object references.
Class Vs Object
Class is a user-defined datatype that has its own data members and member functions whereas an object is an instance of class by which we can access the data members and member functions of the class.
Also called a class variable (in contract to a instance variable)
static in Java
main method is
static, which means that it doesn’t operate on an object.
- But why is
A program terminates all its activity and exits when one of two things happens:
- All the threads that are not daemon threads terminate.
- Some thread invokes the
exitmethod of class
Systemand the exit operation is not forbidden by the security manager.
In other words, the program may exit before or after the
mainmethod finishes; a return value from
mainwould therefore be meaningless. If you want the program to return a status code, call one of the following methods (note that all three methods never return normally):