Saturday, September 25, 2010

• Ways to create object

  • here we can create object in 6 ways. They are
    1. by using new keyword
eg: test t=new test();
    1. by using factory method
eg: thread t= thread.currentthread();
    1. by using a method of java class that return other class object
eg: integer i=new integer(10);
      String s=i. toString ();
Here toString is the method of java.lang.Integer class, constructing or returning another java class object called string object
    1. by using cloning operator,
    2. by using newInstance() method
    3. by using deserialization

No comments:

Post a Comment