封装1-1练习

封装1-1练习

package zuoye;


class student

{

private String name;

private String number;

private String gender;

private int age;

public student(String name,String number,String gender,int age)

{

this.name=name;

this.number=number;

this.gender=gender;

this.age=age;

}

void show()

{

System.out.println("学生信息如下");

System.out.println("姓名:"+this.name);

System.out.println("学号:"+this.number);

System.out.println("性别:"+this.gender);

System.out.println("年龄:"+this.age);

}

public void name(String name)

{

this.name=name;

}

public String name()

{

return name;

}

public void number(String number)

{

this.number=number;

}

public String number()

{

return number;

}

public void String(String gender)

{

this.gender=gender;

}

public String gender()

{

return gender;

}

public void age(int age)

{

this.age=age;

}

public int age()

{

return age;

}

}


class specialty

{

private String classname;

private int year;

public specialty(String classname,int year)

{

this.classname=classname;

this.year=year;

}

void show()

{

System.out.println("学科专业:"+classname);

System.out.println("学制年限:"+year);

}

public void classname(String classname)

{

this.classname=classname;

}

public String classname()

{

return classname;

}

public void year(int year)

{

this.year=year;

}

public int year()

{

return year;

}

}



class abc

{


public static void main(String[] args)

{

student s=new student("王五","S201","男",20);

student s1=new student("李四","S211","女",30);

student s2=new student("张三","S221","男",10);

specialty c=new specialty("计算机应用与技术",4);

s.show();

c.show();

s1.show();

c.show();

s2.show();

c.show();

}

}

麻烦助教和同学看一下需要改正的地方

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
没有马甲线的安琪拉 2017-12-12 11:46:13

封装1-1?哪有这么个练习?哪个小节的?

问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师