Sham
The first question most peopel will ask you is: Did you try to compile it and see if it works?
Originally posted by Sham Usha:
public class Ssupper{
private void setAge(int sAge){
if(sAge >= 100){
System.out.println("You have a long life");
}
}
class Ssub extends Ssupper{
public static void main(String argv[]){
Ssupper b = new Ssupper();
b.setAge(101);
}//End of main
}
}
In your code you have a couple of other errors to take care of before you can
test this:
--Ssub is defined within Ssupper, which makes it an inner class. That is fine to do however because it isn't a static inner class you can't have static method in it. You need to move main outside of Ssub or move Ssub outside of Ssuper.
--If you move Ssub then you'll have to make it public or the jvm wont find your main method (unless these are just helper classes for some other classes).
After you get these taken care of you find that it is giving you an error because setAge is private and can not be accessed outside of Ssupper. Even though it is being accessed by an Ssupper object it is stil being accessed from a class other than Ssupper so it will not compile.
Dave