i have tried the following code in net beans i am expecting error but i didn't get any error
class B {
private void method() {
}
public static void main() {
B b = new B();
B c = new C();
b.method();
c.method();
}
}
class C extends B {
}
When c.method() tries to access the method it should show error but in NetBeans it is not showing. Please tell me what is the fault.
The way you have your method defined, you are calling C.method() from inside B.main(). Since method is private to B, the method is visible inside of B.main() even though the object is of type C which inherits from B.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With