本帖最后由 陈胜 于 2016-2-19 23:33 编辑
大家新年快乐!!! 与大家分享四道多态方面的试题
1...
class test {
public static void main(String[] args) {
Fu f = new Zi();
Zi z = (Zi)f;
f.show();
z.show();
System.out.println(f.output);
System.out.println(z.output);
}
}
class Fu {
public String output="1";
public void show(){
output+=1;
}
}
class Zi extends Fu{
public String output="1";
public void show(){
output+=3;
}
}
2...
class test {
public static void main(String[] args) {
Fu f = new Zi();
Zi z = (Zi)f;
f.show();
z.show();
System.out.println(f.output);
System.out.println(z.output);
}
}
class Fu {
public String output="1";
public void show(){
output+=1;
}
}
class Zi extends Fu{
public void show(){
output+=3;
}
}
3...
class test {
public static void main(String[] args) {
Fu f = new Zi();
Zi z = new Zi();
f.show();
z.show();
System.out.println(f.output);
System.out.println(z.output);
}
}
class Fu {
public String output="1";
public void show(){
output+=1;
}
}
class Zi extends Fu{
public String output="1";
public void show(){
output+=3;
}
}
4...
class test {
public static void main(String[] args) {
Fu f = new Zi();
Zi z = new Zi();
f.show();
z.show();
System.out.println(f.output);
System.out.println(z.output);
}
}
class Fu {
public String output="1";
public void show(){
output+=1;
}
}
class Zi extends Fu{
public void show(){
output+=3;
}
}
|