Sorry I am a newbie to Java. I am trying to get my head around inheritance and subclass/superclass relationships in Java.
If classA is a subclass of classB, will classA\
ClassB's private methods are not visible to ClassA. If you want to give ClassA access to internal methods of ClassB (without those methods becoming part of ClassB's public interface) you should make them protected instead of private.
ClassA will inherit all of classB's public and protected methods. It will NOT include classB's private methods.
Private methods are not inherited. Only protected, public and default methods are inherited.
Class A will provide the methods that are public in both classA and ClassB
All public and protected methods and variables will be inherited. Any methods with the same signature in the subclass will override the superclass behavior. The subclass will not inherit private methods and variables. Default (a.k.a package visibility level) will be inherited if in the same pacakge and by subclasses.
Public methods, labeled by public
are available to every class.
Protected methods, labeled by protected
are available to subclasses and friendly classes, which are classes in the same package.
Friendly methods, labeled by nothing (i.e. default) are available to friendly classes.
Private methods are available only to the class itself.
Static methods, labeled by static
are available to without an object to access them. These are called by ClassName.foo(), SuperClassName.foo() (unnecessary if not overriden, foo() is acceptable), or ClassName.foo() (unnecessary, foo() is acceptable)
Dynamic (check vocab???) labeled by nothing (i.e. default) are available only if one has an object of the class. ex: bar.foo(), this.foo() (unnecessary, foo() is acceptable), or super.foo() (unnecessary if not overridden, foo() is acceptable)
Overriden methods, annotated by @Override
are only available through super.foo
So in an instance of ClassB, all protected
and public
members and methods of ClassA will be accessible. In a static call, only static methods are accessible.
Firstly, the word "inherited" isn't quite the right term. You mean "visible".
public
and protected
are always visibleprivate
is not visible