jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Marcus G exam 1 -58,59 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Marcus G exam 1 -58,59" Watch "Marcus G exam 1 -58,59" New topic

Marcus G exam 1 -58,59

may leung

Joined: Nov 28, 2000
Posts: 23
58. 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
package Base;
class Base{
protected void amethod(){
}//End of amethod
}//End of class base
package Class1;
public class Class1 extends Base{
public static void main(String argv[]){
Base b = new Base();
}//End of main
}//End of Class1
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 ans is 4 but I chose 1. I don't understand what the compile error in 4 said about.

59.class Base{
private void amethod(int iBase){
class Over extends Base{
public static void main(String argv[]){
Over o = new Over();
int iBase=0;
public void amethod(int iOver){
1) Compile time error complaining that Base.amethod is private
2) Runtime error complaining that Base.amethod is private
3) Output of "Base.amethod"
4) Output of "Over.amethod"

the ans is 4. In this overriding, I understand the name of parameter doesn't matter, I want to ask is the base class declare private but supclass declare public, why they still can override?
Kindly explain these for me!!
Cristi Tudose
Ranch Hand

Joined: Dec 25, 2000
Posts: 53
Q59.As u know private members are not inherited,but they do exist in the sub-class.
Since the private methods are not inherited,they cannot be overriden. In Over happens to exist a method
with the same signature as in superclass Base,but it's essentially a new method.
To add,even Base has the method involved as public,now we definitely have ovveriding,but as the
type of the object reffered by obj.ref o is of type Over,we get the same result.
Q58.This is taken from Bruce Eckel:
"It's worth remembering that anytime you create a package, you implicitly specify a directory structure when you give the package a name. The package must live in the directory indicated by its name, which must be a directory that is searchable starting from the CLASSPATH"
So you creat 2 different package and at compile time the class Base isn't found.
But what I don't understand is the final part of the explanation from the answer :
Hope this helps.
"The stuff about File1 not having been compiled was just to mislead, java has the
equivalent of an "automake", whereby if it was not for the package statements the other file would have been automatically
Could someone explain last paragraph?
Best rgds,
I agree. Here's the link: http://aspose.com/file-tools
subject: Marcus G exam 1 -58,59
It's not a secret anymore!