• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

class construction

 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
diff between..
new Horse(); and

Horse horse=new Horse();
 
Ranch Hand
Posts: 157
1
Android MySQL Database Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ritesh please ask questions properly, do that others can understand this.
new Horse(); and Horse horse=new Horse(); are same but new Horse(); here you have created object but you have no reference to it.
You cant use it. instead new Horse().method(); makes sense. But this object becomes eligible for garbage collection as it has no reference from a live thread. Hope this makes sense.
 
Marshal
Posts: 76446
366
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It does make sense, but may be difficult to understand for people not fluent in English.

new Horse() means create a Horse object. You haven’t done anything with it, but you can use it as foo(new Horse); or new Horse().foo()
   You can only use that object once, unless you can retrieve it from another object using it.
Horse h = new Horse() means create a Horse object and apply the name h to it. You can now use it as often as you like, as long as h is in scope and hasn’t been reassigned.
 
Ritesh raushan
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks brother and sorry for short question....
 
Campbell Ritchie
Marshal
Posts: 76446
366
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You’re welcome
 
Creativity is allowing yourself to make mistakes; art is knowing which ones to keep. Keep this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic