aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Marcus Exam 1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Marcus Exam 1 " Watch "Marcus Exam 1 " New topic
Author

Marcus Exam 1

cowboy55
Greenhorn

Joined: Jun 18, 2000
Posts: 14
Hi,
This is based on question from marcus exam but I changed the question a little just to see what would be the output. please read and explain why your output would be true. Thanks =)
-What will be the result when you try to compile and run the following code?
public class Base{
Base(){
int i = 100;
System.out.println(i);
}
}
public class Pri extends Base{
static int i = 200;
public static void main(String argv[]){
Pri p = new Pri();
System.out.println(i);
}
}
Ken Lai
Ranch Hand

Joined: Aug 06, 2000
Posts: 30
Compile time error: 2 public classes in the same file.
I didn't test it out though so feel free to correct me if I'm wrong.
antraarora
Ranch Hand

Joined: Jul 27, 2000
Posts: 45
Compile time error because a class can have ATMOST one top level public class.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
I think cowboy55 didn't mention about both the classes are in the same file, may be they are in two different files like Base.java & pri.java
If they both are in two different files, they both will compile and run and gives the output 100, 200. because the Pri class implictly calls the Base class no-arg constructor and prints that value then it prints Pri class's i value.
Correct me, if I am wrong.
Thanks
VR.
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Thank you all and VR for ur correction.
Yeah, i wanted to know if it would print out 100 , 200.
now i know it does if put on dirrent files.
thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Marcus Exam 1