Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #17427
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!news-out.readnews.com!transit3.readnews.com!news-out.news.tds.net!newsreading01.news.tds.net!53ab2750!not-for-mail |
|---|---|
| From | "dkoleary" <dkoleary@1:261/38.remove-qhs-this> |
| Subject | why does this work? |
| Message-ID | <5022AB86.56377.calajapr@time.synchro.net> (permalink) |
| X-Comment-To | All |
| Newsgroups | comp.lang.java.programmer |
| X-FTN-AREA | COMP.LANG.JAVA.PROGRAMMER |
| X-FTN-MSGID | 1:261/38 4be438ba |
| Content-Type | text/plain; charset=IBM437 |
| Content-Transfer-Encoding | 8bit |
| X-Gateway | time.synchro.net [Synchronet 3.16a-Win32 NewsLink 1.98] |
| Lines | 47 |
| Date | Wed, 08 Aug 2012 19:04:27 GMT |
| NNTP-Posting-Host | 69.21.70.65 |
| X-Complaints-To | news@tds.net |
| X-Trace | newsreading01.news.tds.net 1344452667 69.21.70.65 (Wed, 08 Aug 2012 14:04:27 CDT) |
| NNTP-Posting-Date | Wed, 08 Aug 2012 14:04:27 CDT |
| Organization | tds.net |
| Xref | csiph.com comp.lang.java.programmer:17427 |
Show key headers only | View raw
From: dkoleary <dkoleary@olearycomputers.com>
Hi;
New java programmer. So new, in fact, that I'm still working my way through
the O'Reilly Head First Java book. One of the end of chapter questions
involves identifying if a sample class will compile and what to do to make it
compile if it won't.
The sample class from chapter 4 is:
class XCopy
{ public static void main(String[] args)
{ int orig = 42;
XCopy x = new XCopy();
int y = x.go(orig);
System.out.println(orig + " " + y);
}
int go(int arg)
{ return arg * 2; }
}
The book says that it'll compile and run, displaying "42 84" and, sure enough,
it does:
$ javac XCopy.java
$ java XCopy
42 84
How come that isn't recursive? XCopy.main() instantiates a new XCopy.
Shouldn't that new XCopy instance also instantiate a new XCopy?
I was figuring this would run until the XCopy.go function tried returning a
number that wouldn't fit in int anymore... That's obviously not the case, but I
don't know why.
Can someone provide the missing concept?
Thanks.
Doug O'Leary
--- BBBS/Li6 v4.10 Dada-1
* Origin: Prism bbs (1:261/38)
--- Synchronet 3.16a-Win32 NewsLink 1.98
Time Warp of the Future BBS - telnet://time.synchro.net:24
Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread
why does this work? "dkoleary" <dkoleary@1:261/38.remove-qhs-this> - 2012-08-08 19:04 +0000
Re: why does this work? "Daniel Pitts" <daniel.pitts@1:261/38.remove-qhs-this> - 2012-08-08 19:04 +0000
Re: why does this work? "dkoleary" <dkoleary@1:261/38.remove-k2r-this> - 2012-08-09 18:44 +0000
Re: why does this work? "Lew" <lew@1:261/38.remove-k2r-this> - 2012-08-09 18:44 +0000
Re: why does this work? "Eric Sosman" <eric.sosman@1:261/38.remove-r72-this> - 2012-08-08 20:06 +0000
Re: why does this work? "Roedy Green" <roedy.green@1:261/38.remove-k2r-this> - 2012-08-09 18:44 +0000
Re: why does this work? "glen herrmannsfeldt" <glen.herrmannsfeldt@1:261/38.remove-t9h-this> - 2012-08-10 18:39 +0000
csiph-web