您的位置:首页 > 其它

内部类

2014-05-06 14:44 183 查看
package st;
//内部类
class RedCowForm
{
static String formName;
RedCow cow;
RedCowForm(){}
RedCowForm(String s){
cow = new RedCow(150,112,5000);
formName=s;
}
public void ShowCowMess()
{
cow.speak();
}
class RedCow  //内部类的声明
{
String cowName ="红牛";
int height , weight , price;
RedCow(int h ,int w, int p)
{
height=h;
weight=w;
price=p;
}
void  speak()
{
System.out.println("偶是"+cowName+",身高:"+height+"cm 体重: "+weight+"kg,生活在"+formName);
}
}
}
public class example_1
{
public static void main(String args[])
{
RedCowForm form = new  RedCowForm("红牛农场");
form.ShowCowMess();
form.cow.speak();
}
}


内部类
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: