Declaring Objects (Instantiating a Class)


When an object of a class is created, the class is said to be instantiated. All the instances share the attributes and behavior of the class. But the values of those attributes; i.e., the state is unique for each object.

A single class may have any number of instances. As we declare variables like (type name;), this notifies the compiler that we will use name to refer to data whose type is type.

With a primitive variable, this declaration also reserves the proper amount of memory for the variable. So for reference variable, type must be strictly a concrete class name. In general, we can’t create objects of an abstract class or an interface.
     Dog tuffy;
If we declare reference variable (tuffy) like this, its value will be undetermined (null) until an object is actually created and assigned to it. Simply declaring a reference variable does not create an object.

Review: Object Features
    Which is NOT one of the features of objects?

      Behavior
      Cohension
      Identity
      State
        Result:




      When I was a kid, I used to pray every night for a new bike.    
      Then I realized that God doesn’t work that way.    
      So I stole a bike and asked Him to forgive me.    
      - Emo Phillips