aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is the type of Base? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what is the type of Base?" Watch "what is the type of Base?" New topic
Author

what is the type of Base?

Yingie Pitts
Ranch Hand

Joined: Oct 10, 2002
Posts: 37
Below is a question from one of the mock exams. But I have a question related to Base class. It can not be protected and private. If it is public, it has to be declared in a seperate file named Base.java. So what type of the Base is if I save both of the class in one file named Child.java?

class Base{
public void amethod(int i, String s){
System.out.println("Base amethod");
}
Base(){
System.out.println("Base Constructor");
}
}
public class Child extends Base{
int i;
String Parm="Hello";
public static void main(String argv[]){
Child c = new Child();
c.amethod();
}
void amethod(int i, String Parm){
super.amethod(i,Parm);
}
public void amethod(){}
}
1) Compile time error
2) Error caused by illegal syntax super.amethod(i,Parm)
3) Output of "Base Constructor"
4) Error caused by incorrect parameter names in call to super.amethod
answer: 1)


"To err is human, but to really foul things up you need a computer." Paul Ehrlich.
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
hi:
I believe it has defualt access. It will be accessable from classes within the same package.
Hanna


SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
Dhanashree Mankar
Ranch Hand

Joined: Aug 25, 2003
Posts: 123
Originally posted by Yingie Pitts:
Below is a question from one of the mock exams. But I have a question related to Base class. It can not be protected and private. If it is public, it has to be declared in a seperate file named Base.java. So what type of the Base is if I save both of the class in one file named Child.java?

class Base{
public void amethod(int i, String s){
System.out.println("Base amethod");
}
Base(){
System.out.println("Base Constructor");
}
}
public class Child extends Base{
int i;
String Parm="Hello";
public static void main(String argv[]){
Child c = new Child();
c.amethod();
}
void amethod(int i, String Parm){
super.amethod(i,Parm);
}
public void amethod(){}
}
1) Compile time error
2) Error caused by illegal syntax super.amethod(i,Parm)
3) Output of "Base Constructor"
4) Error caused by incorrect parameter names in call to super.amethod
answer: 1)

compile time error is due to overriding of amethod() from base class.
It's accessibility is public and in subclass it is default so compile time error.
Yingie Pitts
Ranch Hand

Joined: Oct 10, 2002
Posts: 37
I have been considering defualt class as private type class. But it seems default is just default; it does not mean it is of any type. The only thing about default class is that it only can be accessed within the same package. Am I right?
chi Lin
Ranch Hand

Joined: Aug 24, 2001
Posts: 348
Yes, there is no default type, we refer it this way when no modifier is specified & it can be accessed within same package.
access relationship from narrow to wide is
private -> default -> protected -> public


not so smart guy still curious to learn new stuff every now and then
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: what is the type of Base?