封装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
- 参与学习 人
- 提交作业 7317 份
- 解答问题 14452 个
想要入门学编程?多年一直活跃在编程语言排行版前列的Java是一个很好的选择。本路径将从Java基础语法、面向对象、常用工具类三部分,为你开启软件开发的大门!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星