Time: 2004-6-04 20:24:22 Title:
The topic is a bit leak, correct it.
Java code:
Child C =
New child
(
);
PARENT P = C;
p.
(
);
C.
(
);
Create a CHILD instance c, then assign a variable P pointing to the Child Ancestor Parent, then call P.Print () C.Print (), and print results are different. The code in the Parent class print () is: system.out.println ("parent"); the code in the Child class print () is: system.out.println ("child"); execution result: Parent Child This and more The principle of state conflicts, who knows the answer? I don't dare to reveal, or I will be more cost-effective to you, - .. = The code is as follows, take a closer look at the perception:
Java code:
Package pent;
Import Child.
CHILD;
public
Class Parent
{
Void Print
(
)
{
SYSTEM.
OUT.
PRINTLN
("Parent"
);
}
public
Static
Void Main
(
String
[
] argg
)
{
Child C =
New child
(
);
PARENT P = C;
p.
(
);
C.
(
);
}
}
Java code:
Package child;
Import parent.
Parent;
public
Class Child
Extends Parent
{
public
Void Print
(
)
{
SYSTEM.
OUT.
PRINTLN
("Child"
);
}
}
Main reason two classes are not in the same bag
Time: 2004-6-11 11:12:47 Title:
When the method does not write a domain, the default is Friendly, and Friendly's scope only limits the domain of the same package. For children and grandchildren, it is exceeded her role, so this is not Override.