The java main() method and an Object creation process (#4)


----------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.

1 comment :

  1. Do you understand there's a 12 word sentence you can say to your man... that will induce intense emotions of love and impulsive attraction for you buried within his heart?

    That's because hidden in these 12 words is a "secret signal" that triggers a man's instinct to love, please and care for you with all his heart...

    ====> 12 Words Who Fuel A Man's Love Impulse

    This instinct is so hardwired into a man's genetics that it will make him work better than ever before to make your relationship as strong as it can be.

    In fact, fueling this mighty instinct is so binding to having the best possible relationship with your man that as soon as you send your man one of these "Secret Signals"...

    ...You will soon notice him expose his heart and mind for you in a way he never experienced before and he'll recognize you as the only woman in the galaxy who has ever truly attracted him.

    ReplyDelete