<span style= "FONT-SIZE:18PX;" >import java.util.*;p ublic class sixtysixth { public static void main ( String[] args) { SYSTEM.OUT.PRINTLN (New Child (). Name); System.out.println (New Child (). Count); System.out.println (New Child (). Parent); System.out.println ((Base) New Child ()). Count); System.out.println ((Base) New Child ()). Name); // System.out.println ((Base) New Child ()). Uniq); Child.fun ();//Call Subclass hidden methods new Child (). F1 ()//Call the subclass inherited method, call the overridden F () in F1 () }}class Child extends base{ public String Name = "Child";//mask non-static name public static int count=100;//of the parent class The static count public static int uniq = 200;//Subclass unique static is masked by the parent class public static void Fun () { System.out.println ("Fun:child"); } public void f () { System.out.println ("override"); } }clbase{ Public String name = "Base"; public static int count = 0; public static int parent=5;//parent class unique Static & nbsp; public int BC = 6;//non-static BC unique to parent class, can be inherited by quilt class Public Base () { count++; } public void F1 () { f (); } public static void Fun () { System.out.println ("Fun:base"); //f (); } public void f () { System.out.println (" Original "); }}</span>
Child
100
5
4
Base
Fun:child
Override
About inheritance
Static methods, general methods and static properties, the general properties will be the Quilt class inheritance, but only the general method can be overridden, polymorphic, the other three are inherited or hidden.
If it is hidden, then access is the attribute in the subclass, whether it is reasonable or not.
Such as:
Import java.util.*;p Ublic class Sixtysixth {public static void Main (string[] args) { System.out.println (new C () . a);} } Class C extends b{ private int a = 0;} Class b{public int a = 1;}
Who is the person who is visiting a? Is it output 0 or 1?
Sixtysixth.java:12: Error: A can access privateSystem.out.println (new C (). a) in C; ^1 a mistake.
Neither output 0 nor output 1, but an error. That is, after the hidden property, only in the class with super access to the hidden properties or methods.
Import java.util.*;p Ublic class Sixtysixth {public static void Main (string[] args) { new C (). f (); }} Class C extends b{ private int a = 0; public void F () { System.out.println ("My A=" +a); System.out.println ("A= of My Father's class" +super.a);} } Class b{public int a = 1;}
My a=0, the a=1 of my father's class.
Properties of Java doubts hidden