JAvaの継承黒馬プログラマー
2868 ワード
。Java java.lang.Object 。 , 。 private 。
, 。 Java , 。
---------------------- <a href="http://www.itheima.com"target="blank">ASP.Net+Unity </a>、<a href="http://www.itheima.com"target="blank">.Net </a>、 ! ----------------------
class A
{
A(){}
private int x=10;//A ( )
protected int y=20;//A ( )
void fun()//A fun ( )
{
System.out.println("y+x="+(y+x));//
}
}
class B extends A// B A
{
B(){}
void gun()// B
{
y=y+1;// y 1
System.out.println("y="+y);
}
}
public class test2 {
public static void main(String args[])//
{
B b =new B();
b.gun();
b.fun();
b.gun();
}
}
B fun X……
:
y=21
y+x=31
y=22
---------------------- <a href="http://www.itheima.com"target="blank">ASP.Net+Unity </a>、<a href="http://www.itheima.com"target="blank">.Net </a>、 ! ----------------------