----------Object creation by JVM-----------
Description:
The object car1 is an instance of Car class created by JVM.As shown below the new keyword is use to create car1 object from the Car class.
Car car1 = new Car();
Car class Reference -> http://namastejava.blogspot.jp/2015/01/java-source-translation-to-class-file-3.html
Each object is isolated from each other and maintains their own state (value for each property). e.g. car1 object’s price = 1000000, where as car2 object’s price = 2000.
-----------Source [CarApp.java]------------
public class CarApp {
public static void main(String[] args) {
//car1 instance
Car car1 = new Car();
car1.setPrice(1000000);
car1.setCurrency("JPY");
double p1 = car1.getPrice();
String c1 = car1.getCurrency();
System.out.println("Price1 = " + p1);
System.out.println("Currency1 = " + c1);
//car2 instance
Car car2 = new Car();
car2.setPrice(2000);
car2.setCurrency("USD");
//car3 instance
Car car3 = new Car();
car3.setPrice(5000);
car3.setCurrency("EUR");
}
}
Description:
The main() method
- is an entry point to the Application
- is a special method, which is already known to JVM
- should exist for each Java application
- is static, hence JVM can access it without Instance of the target class
- returns void
- takes parameters of type String array, these are use to pass values at the time of application start up.