Results 1 to 5 of 5
Thread: objects from non static class
- 05-15-2012, 06:37 PM #1
Senior Member
- Join Date
- Jan 2012
- Posts
- 142
- Rep Power
- 0
objects from non static class
I read that whenever we have a non-static class, in order to instantiated, the object needs to be created for the class type.
However lets say I have public class pear. Why does the code new pear(); instantiate? Is there an object being created and if so how do I access it as it has no name.
The way I learnt it was: pear a = new pear();
Thanks for your time
- 05-15-2012, 06:44 PM #2
Re: objects from non static class
new pear(); //call the class's constructor. The value returned is not saved in a variable.
Math.sqrt(334); // value returned is not saved in a variableLast edited by Norm; 05-15-2012 at 06:47 PM.
If you don't understand my response, don't ignore it, ask a question.
- 05-15-2012, 06:49 PM #3
Senior Member
- Join Date
- Jan 2012
- Posts
- 142
- Rep Power
- 0
Re: objects from non static class
if I had a method print, could I use: new pear().print(); ?
- 05-15-2012, 06:54 PM #4
Re: objects from non static class
Try it and see what happens.
If you don't understand my response, don't ignore it, ask a question.
- 05-15-2012, 06:55 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,427
- Blog Entries
- 7
- Rep Power
- 17
Re: objects from non static class
When people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Can non-static Inner Class have static fields ?
By fatabass in forum New To JavaReplies: 3Last Post: 02-05-2012, 09:47 PM -
Static and non static class methods question
By silverglade in forum New To JavaReplies: 2Last Post: 05-14-2011, 10:10 PM -
Why can't a static method create inner class objects
By Humbly in forum New To JavaReplies: 6Last Post: 02-12-2011, 06:56 AM -
referencing objects from static method
By talktofrank in forum New To JavaReplies: 4Last Post: 10-26-2009, 06:09 PM -
Static method cannot make new objects?
By zerkz in forum New To JavaReplies: 2Last Post: 10-15-2009, 03:17 AM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks