class base{
???? intx = 1;
???? staticinty = 2;
???? String name () {
???????? return"mother";
????}
???? static String Staticname () {
???????? return"static mother";
????}
}
class Subclass extends base{
???? intx = 4;
???? inty = 5;
???? String name () {
???????? return"Baby";
????}
???? static String Staticname () {
???????? return"static Baby";
????}
}
Public class test02{
???? Public staticvoid main (string[] args) {
???????? Subclass s = new subclass ();
???????? System. out. println (S.x+""+s.y+ ""+s.name () + ""+s. Staticname ());
???????? Base S1 = s;
???????? System. out. println (S1. X+""+s1. y + ""+s1.name () +""+s1. Staticname());
????}
}
?
/*
Results:
?
4 5 Baby static Baby
1 2 baby static mother
Conclusion:
?
instance method of the parent class overridden by an instance method of the same name as the quilt class
static method of parent class The quilt class with the same name static method hidden
instance variables and class variables of the parent class can be hidden by instance variables and class variables of the class
?
just " Base S1 = S " For example : the s Assigns a value to s1 s (subclass) method name name static name
assign a value to S1 after the S1 of the name the method has become "Baby", and Staticname method is only hidden and not overwritten, and now it has been restored "Static Mother"
*/
Hiding and overwriting of Java subclasses and parent class methods