1 Replies - 323 Views - Last Post: 19 July 2011 - 05:50 PM Rate Topic: -----

#1 ZeroDayBro  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 19-July 11

Difference between these 2 methods to define an instance of Object?

Posted 19 July 2011 - 05:44 PM

I stumbled across this method accidently; Eclipse auto-corrected me and turned this up:
java.lang.Object x = new Object();
Object y = new Object();
What's the difference between these two methods of defining an instance of Object?

This post has been edited by ZeroDayBro: 19 July 2011 - 05:45 PM

Is This A Good Question/Topic? 0
  • +

Replies To: Difference between these 2 methods to define an instance of Object?

#2 fromTheSprawl  Icon User is offline

  • Monomania
  • member icon

Reputation: 513
  • View blog
  • Posts: 2,056
  • Joined: 28-December 10

Re: Difference between these 2 methods to define an instance of Object?

Posted 19 July 2011 - 05:50 PM

With the first statement you don't need to import the Object class however, the Object class is the superclass of all Java classes and will be imported no matter what.

You can also try instanciating other classes using the first notation. However you do not see that often since importing the class\package needed at the top of the Java class is the way to go to avoid the long typing and to make the methods available to you easily.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1