Creating an Object ?
A Class Provides the blueprints for
objects. So basically an object is created from a class. In java, the new keyword
is used to created new objects.
There
are three steps to create an object from class:
1)
Declaration:
A variable declaration with a variable name
with an object type.
2)
Instantiation:
The “New” keyword is used to create the
object.
3)
Initialization:
The “New “ keyword is followed by a call
to a constructor. This call initializes the new object.
Let’s see an example for
better understanding about it.
public class Puppy{ public Puppy(String name){//Constructor System.out.println("passed the Name is:"+name ); } public static void main(String args[]){ Puppy myPuppy =new Puppy("tommy"); } }
0 comments:
Post a Comment