This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I am studying for the Sun Java Cert exam and this problem appeared on a mock exam. What will happen when you attempt to compile the following in a Test.java file? class Base{ public static void main(String[] args) { System.out.println("Hello"); } } public class Test extends Base{} Well, I got it wrong but when i ran it myself it outputs "Hello." My question is...I though there could only be one default or public class in a source file. If that is true, then why is this code successful? Thanks JL
Bosun Bello
Ranch Hand
Joined: Nov 06, 2000
Posts: 1506
posted
0
There could only be one public top level class (ie. not an inner class) The public class should have the same name as the filename. i.e yourPublicClassName.java Bosun
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
Remember class test "is a" base and therefore inherits the methods of base, including main.
"JavaRanch, where the deer and the Certified play" - David O'Meara
herb slocomb
Ranch Hand
Joined: Feb 12, 2001
Posts: 1479
posted
0
Only one public class per source file is the rule I heard and I only see one here. [This message has been edited by herb slocomb (edited March 22, 2001).]
ryan burgdorfer
Ranch Hand
Joined: Jan 24, 2001
Posts: 219
posted
0
JL, What were the choices for an answer? What did you pick out of those choices, and what was given as the correct answer? Thanks, ------------------