class father
{
int a=1,6=2;
void show()
{
System.out.println(a+" "+b);
}
}
class som extends father
{
int b=3,c=4;
void show()
{
system.out.println(a+" "+b+" "+c); }
}
class jex6_24
{
public static void main(string[] args)
{
son S =new son();
S.show();
farther Fb=S;
Fb.show();
System.out.println(Fb.a+""+Fb.b);
if(Fb instanceof son)
S=(son)Fb;
System.out.println(S.a+""+S.b+""+S.c);
}
}
{
int a=1,6=2;
void show()
{
System.out.println(a+" "+b);
}
}
class som extends father
{
int b=3,c=4;
void show()
{
system.out.println(a+" "+b+" "+c); }
}
class jex6_24
{
public static void main(string[] args)
{
son S =new son();
S.show();
farther Fb=S;
Fb.show();
System.out.println(Fb.a+""+Fb.b);
if(Fb instanceof son)
S=(son)Fb;
System.out.println(S.a+""+S.b+""+S.c);
}
}
解决方案 »
- 求高手指点:java.io.FileNotFoundException: D:\晋级\jdbc\01_传智播客JDBC_jdbc的理论概述 (拒绝访问。)
- 从InputStream获取并播放Audio文件。声音格式为au
- 可不可以简单的说下structs,hibernate和spring在java中的应用?谢谢回答
- 下面这段怎么老是无穷循环呀???
- Soket问题
- 大虾给偶看看这小段代码
- 服务器端socket传过来的数据用BufferedReader的read方法接收,存在发送过来读不到的情况,为什么呀?
- 类型转换
- 快就我,编译通过java执行出错,解答者有冰淇淋吃
- Apache+Resin4.0发布JSP
- JAVA程序设计啊·帮帮我吧
- 关于内部类的问题
son S =new son(); //代码错误
int a=1,6=2;
子类对象引用问题
这个怎么了??
1. 在class father 中6=2,这里可能是b=2;
2. class som extends father 这里类的名字应该是son,你把n写成m。
3. 还是在son类中,system.out.println(a+" "+b+" "+c); //这里的system的S应该是大写的--〉System
4.jex6_24中public static void main(string[] args) {//这里的string[]中的S应该是大写的--〉String
5.jex6_24中farther Fb = S;//这里应该是把farther--〉father .多了一个r。
{
int a=1,b=2;
void show()
{
System.out.println(a+" "+b);
}
}
class son extends farther
{
int b=3,c=4;
void show()
{
System.out.println(a+" "+b+" "+c); }
}
public class jex6_24
{
public static void main(String[] args)
{
son S =new son();
S.show();
farther Fb=S;
Fb.show();
System.out.println(Fb.a+" "+Fb.b);
//if(Fb instanceof son)
S=(son)Fb;
System.out.println(S.a+" "+S.b+" "+S.c);
}
}
输出:
1 3 4
1 3 4
1 2
1 3 4farther Fb=S; 形成多态,show方法只调用子类重写的方法。但是属性不重写。
{
int a=1,b=2;
void show()
{
System.out.println(a+" "+b);
}
}
class Son extends Father
{
int b=3,c=4;
void show()
{
System.out.println(a+" "+b+" "+c); }
}
class Test1
{
public static void main(String[] args)
{
Son S =new Son();
S.show();
Father Fb=S;
Fb.show();
System.out.println(Fb.a+""+Fb.b);
if(Fb instanceof Father)
S=(Son)Fb;
System.out.println(S.a+""+S.b+""+S.c);
}
}
楼上说的很对,属性是不会被重写的,子类会把父类中的方法覆盖住
我汗~~~估计楼主是想当高手,用记事本写代码~~~~找个IDE用用吧~~~
class Father {
int a = 1;
int b = 2; void show() {
System.out.println(a + " " + b);
}
}class Son extends Father {
int b = 3, c = 4; void show() {
System.out.println(a + " " + b + " " + c); }
}public class jex6_24 {
public static void main(String[] args) {
Son S = new Son();
S.show();
Father Fb = S;
Fb.show();
System.out.println(Fb.a + "" + Fb.b);
if (Fb instanceof Son)
S = (Son) Fb;
System.out.println(S.a + "" + S.b + "" + S.c);
}
}