java吧 关注:1,250,875贴子:12,734,881
  • 0回复贴,共1

<小白请教> 关于类和this

取消只看楼主收藏回复

class A {
void fun1() {
System.out.println(this.fun2());
}
int fun2() {
return 123;
}
}
class B extends A {
int fun2() {
return 456;
}
public static void main(String argv[]) {
A a;
B b = new B();
b.fun1();
a= b;
a.fun1();
}
}
我想问一下 为什么在main里这个A a 是怎么创建的没有new也可以吗?
还有就是a=b;能理解大概的意思 但是说不明白.
这些和继承的作用有什么关系?
求大神解答


1楼2017-02-19 13:00回复