Inherited methods access level..

Hello,

I have two classes.X and Y . Y extends X.

class X{

public X(){

System.out.print("default");

}

public X(int x){

}

int f1(int a){

System.out.print("f1 "+a);

return 1;

}

}

class Yextends X{

public Y(int y){

}

protectedint f1(int a){

System.out.print("f1"+a);

return 1;

}

}

The f1 method in X class has default scope but f1 method in Y class has protected scope. default scope is wider than protected class.

so why didn't the compiler argued about this?

[1533 byte] By [xyzta] at [2007-11-26 18:21:50]
# 1

> default scope is wider than protected class

It's actually the other way around: protected scope is wider than default scope.

Protected scope makes a method visible in subclasses and throughout the current package; Default scope makes a method visible throughout the current package.

DrLaszloJamfa at 2007-7-9 5:55:43 > top of Java-index,Java Essentials,Java Programming...
# 2

> The f1 method in X class has default scope but f1 method in Y class

> has protected scope. default scope is wider than protected class.

Nope, it's the other way around. Default scoped things are not visible

anywhere outside the package while protected thingies are visible

*in* the package as well as in anything extending that particular class.

kind regards,

Jos

JosAHa at 2007-7-9 5:55:43 > top of Java-index,Java Essentials,Java Programming...
# 3
old sod, slowest, me again ...kind regards,Jos ;-)
JosAHa at 2007-7-9 5:55:43 > top of Java-index,Java Essentials,Java Programming...