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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Marcus Green "package question"" Watch "Marcus Green "package question"" New topic
Author

Marcus Green "package question"

Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707

You have these files in the same directory. What will happen when you attempt to compile and run Class1.java if you have not already compiled Base.java




1) Compile Error: Methods in Base not found
2) Compile Error: Unable to access protected method in base class
3) Compilation followed by the output "amethod"
4)Compile error: Superclass Class1.Base of class Class1.Class1 not found


The answer is (4)
Can anybody tell the reason!



Regards,
cmbhatt
[ April 17, 2007: Message edited by: Chandra Bhatt ]

cmbhatt
Jesse Custer
Ranch Hand

Joined: Feb 07, 2007
Posts: 45
Did you correctly paste the code?
The question states that both classes are in the same directory, so it makes no sense that they are in different packages.
If you remove the package declarations from the code then you'll see that answer 4 is indeed correct.
Chandra Bhatt
Ranch Hand

Joined: Feb 28, 2007
Posts: 1707
Yup Custer, I have correctly pasted the code, the answer to this question says
"This question tried to make you fool against the automake feature of the javac if classfile(that your class is referencing to) doesn't exist it will automatically create that too".

But this is not the issue!


Did you get the question? Please tell me the correct answer!


Regards,
cmbhatt
swarna dasa
Ranch Hand

Joined: Mar 15, 2007
Posts: 108
I am not sure if the import statement fixes the glitch.

Base (Class) itself has default access. So the class is not visible outside the package.

Let the two files be in the same directory or different directory, when you try to compile Class1
a) It should be under a directory Class1. (Class1/Class1.java)
b) Since there was no import statement for Base, the compiler assumes that Base is in the same directory, so searches for Class1.Base and doesn't find it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Marcus Green "package question"