Java中对数组数据类型理解的举例

package p54_p60.f222_230.ch02;


class p0{}


class person{ //父类

int a;

//person(){}

}


class student extends person{//子类

//student(){}

int x;

}


public class testArray {

p0 p00;

static person ps[]=new person[3];

student st1,st2,st3;


public static void main(String args[]){

testArray tt=new testArray();

tt.st1=new student();

tt.st2=new student();

tt.st3=new student();

ps[0]=tt.st1;

ps[0]=new person();


ps[1]=tt.st2;

ps[2]=tt.st3;

// ps[0]=tt.p00=new p0(); //类型不匹配 不兼容 不能存到person数组中

}

}

对于数据类型为基本类型,操作代码同C语言,対于类型为抽象数据类型/引用类型,情况略复杂一些。一般定义一个引用类型数组,那么该类型的对象及其子类型的对象,均可以存储于该数组,并可借此机会实现多态、动态绑定,从而设计出更加灵活的程序。

展开阅读全文

页面更新:2024-05-20

标签:数组   数据类型   子类   借此机会   绑定   抽象   灵活   定义   对象   类型   语言   情况   代码   操作   程序   科技

1 2 3 4 5

上滑加载更多 ↓
推荐阅读:
友情链接:
更多:

本站资料均由网友自行发布提供,仅用于学习交流。如有版权问题,请与我联系,QQ:4156828  

© CopyRight 2020-2024 All Rights Reserved. Powered By 71396.com 闽ICP备11008920号-4
闽公网安备35020302034903号

Top