\\ //<BR>~\// irucidal~
Originally posted by kevin jia:
Hi,
Because we have only one class it's name is Inner(top-level), for nested class it's name is Test.Inner. I change the code , this time compiler will constructs nested Inner, not top-level Inner. Try this:
public class Test {
public Test() {
new Inner();
}
class Inner {
Inner() {
System.out.println("yer runin' me!");
}
}
public static void main(String[] args) {
new Test();
new Test().new Inner();
}
}
class Inner {
Inner() {
System.out.println("how strange!");
}
}
The answer will be:
"yer runin' me!"
"yer runin' me!"
"yer runin' me!"
Oh, it's wonderful!
SCJP,SCWCD,SCBCD<br />If Opportunity doesn't knock then build the door
Originally posted by Khalid Bou-Rabee:
[b]1] If the following code is compiled, what will the output be? (Don't cheat! I made this one up!)
<pre>
import java.io.*;
import java.awt.event.*;
public class test {
public test() {
new inner();
class inner {
inner() {
System.out.println("yer runnin' me!");
}
}
}
public static void main(String arg[]) {
new test();
}
}
class inner {
inner() {
System.out.println("how strange!");
}
}
</pre>
A) how strange!
B) yer runnin' me!
C) Compiler Error, because you cannot have duplicate class names
D) Runtime Exeption, because duplicate class names detected.
Yours,
Khalid
<pre>
ps: Compile it, find out what the answer is... try switching around the order of the constructor...
</pre>
[This message has been edited by Khalid Bou-Rabee (edited July 17, 2000).][/B]
SCJP,SCWCD,SCBCD<br />If Opportunity doesn't knock then build the door
\\ //<BR>~\// irucidal~
\\ //<BR>~\// irucidal~
Watchya got in that poodle gun? Anything for me? Or this tiny ad?
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
|