seen it in uni lecture notes
How can a Class create an instance of itself before you have finished writing it?
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
SCJP5 ,SCWCD5
james dunster wrote:If you are going to criticise my use of vernacular English then perhaps in your posts you should use punctuation, at least one verb in a sentence and the indefinite article where required.
anyone hv a helpful answer 4 me?
Vijitha Kumara wrote:Please use real words when posting
Vijitha Kumara wrote:Please use real words when posting (uni instead University).
How can a Class create an instance of itself before you have finished writing it?
Campbell Ritchie wrote:Apologies expected, please.
Campbell Ritchie wrote:Shut up both of you. Apologies expected, please.
Abhijit Rai wrote:Hey James,
Just a couple of points
1. The code is not getting executed as soon as you finish writing the code,(First the .java file is compiled into a .class file and then the.class file is executed ).You first gotta save it with a .java extension (eg XCopy.java).
2.Next compile it .To compile the code ,one way would be using javac Xcopy.java command in DOS(ie Windows).
3.Having got the .class file you can now run it on the java virtual machine one way is would be using java XCopy again in DOS.At this step the execution actually occurs .
Now you should notice that when this step is reached there is a complete Java class (XCopy.class )available to the interpreter to make an object of .Hence an object is being created of a complete Java class .
Now when the JVM encounters " XCopy ref=new XCopy() "it creates an object of this class and assigns it to reference "ref".Think of a class as a professor's Lecture notes,now the Professor wont let you have his originals so you have to get it xeroxed .The copy of the originals can be thought of as the object .Hence you may have any number of copies(objects) of a professors original Lecture notes(Class).
Moreover you should go through the discussions about static members in any good book ,I would recommend :
Head first Java,Thinking in Java HTH
I would guess so... this is mostly a very friendly place! Though the occasional polite dispute/debate has been known.james dunster wrote:Or am I taking this seriously when I shouldn't?
How can a Class create an instance of itself before you have finished writing it?
Charles Lyons wrote:
Vijitha Kumara wrote:Please use real words when posting (uni instead University).
Actually, "uni" is listed in the OED as a "chiefly Australian colloquial term for university", though we've adopted it in the UK too. I therefore consider it a real word.
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
That is basically an example of recursion where the recursive function is the constructor for the object. Recursion is fundamentally a procedural concept, but the key here (which makes this OOP rather than procedural) is that the recursion happens inside the constructor and before the display() method is invoked on each object.james dunster wrote:So that explains why in Salvin Francis' piece of code you can see the value of n go from 20 to 5 before the new objects are made and then from 5 to 20 after/ Not quite sure why it delivers them in opposite order from how they were made.
So that explains why in Salvin Francis' piece of code you can see the value of n go from 20 to 5 before the new objects are made and then from 5 to 20 after/ Not quite sure why it delivers them in opposite order from how they were made;
SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Charles Lyons wrote:
james dunster wrote:So that explains why in Salvin Francis' piece of code you can see the value of n go from 20 to 5 before the new objects are made and then from 5 to 20 after/ Not quite sure why it delivers them in opposite order ~snip
I understood all of that and now also Silvan Francis' post for which thanks. To those of you still bleating on about the use of the word uni ............wel nvm.
It wasn't you I meant. You didn't do anything wrong.Charles Lyons wrote: I'm sorry
Silvan
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|