Objects
Objects
Objects
Creating objects
• object is an instance of the class (house → blueprint)
• new object is created using a keyword new :
$ java MyApp
// in file MyApp.java
New student is created.
public class MyApp {
// YES!
}
Order of initialization
• the code between two brackets {...} is called code block
• instance initializer - code block outside the method
• order of initialization:
1. elds and instance initializer blocks in order in which they appear
public Dog() { 2
name = "Teddy";
} 1
{ System.out.println("Inside the initializer block..."); }