lab5打卡

PART I:

最后一问其实没太看懂。。

 1 package lab5;
 2 
 3 public class Tester{
 4     public Tester(){
 5     }
 6     public void test() {
 7         System.out.println("test!");
 8     }
 9     public static void main(String[] args) {
10         Tester X=new Tester();
11         Tester2 Y=new Tester2();
12         X=Y;        
13       //Y=X;  //compile-time error;
14         Y=(Tester2)X;
15         X=new Tester();
16       //Y=(Tester2)X;//runtime error;
17 /**********************************************************/
18         Tester[] xa;
19         Tester2[] ya=new Tester2[2];
20         xa=ya;
21       //ya=xa; //compile-time error; 
22 /**********************************************************/
23         ya=new Tester2[2];
24         ya=(Tester2[])xa;
25         xa=ya;
26 /**********************************************************/
27         xa=new Tester[2];
28         xa[0]=new Tester();
29         xa[1]=new Tester();
30         xa[0]=ya[0];
31       //ya[0]=xa[0]; //compile-time error;
32       //ya=(Tester2[])xa;//runtime error;
33     }
34      
35 }
View Code

PART II:

 1 package lab5;
 2 
 3 public class T3 extends Tester implements T0{
 4       T3(){         
 5       }
 6       public static void main(String[] args) {
 7           Tester shh=new T3();
 8           T3 hihi=new T3();
 9           shh.test();
10           hihi.test();
11       }
12 }
View Code
1 package lab5;
2 
3 public interface T0 {
4     public void test();
5 }
View Code

(a)YES

(b)NO

(c)NO

(d)YES

 PART III:

PART IV:

 

 

(a)    It will call the subclass method

(b)    run-time error、

(c)

 

posted @ 2017-08-17 00:01  tjxtjx  阅读(106)  评论(0编辑  收藏  举报