定义一个表示学生的类student,私有成员变量:学号no、姓名name、性别sex和年龄 age;定义构造方法初始化
2个回答
展开全部
public class Student
{
private int no;
private String name;
private String sex;
private int age;
public Student(int no,String name,String sex,int age)
{
this.no = no;
this.name=name;
this.sex=sex;
this.age=age
}
public void print()
{
System.out.println("age:"+age+" name:"+name+" sex:"+sex+" age:"+age);
}
public static void main(String []age)
{
Student s=new Student(1,"baidu","GG",20);
s.print();
}
}
{
private int no;
private String name;
private String sex;
private int age;
public Student(int no,String name,String sex,int age)
{
this.no = no;
this.name=name;
this.sex=sex;
this.age=age
}
public void print()
{
System.out.println("age:"+age+" name:"+name+" sex:"+sex+" age:"+age);
}
public static void main(String []age)
{
Student s=new Student(1,"baidu","GG",20);
s.print();
}
}
更多追问追答
追问
这是不是你自己写的哦,对了题目还没有写完
定义一个表示学生的类student,私有成员变量:学号no、姓名name、性别sex和年龄
age;定义构造方法初始化所有成员变量;定义String printInfo()方法把所有成员变量信息
组合成一个字符串返回。在主类中测试。
追答
废话,当然是自己写,
public void print()
{
System.out.println("age:"+age+" name:"+name+" sex:"+sex+" age:"+age);
}
把上面的方法改成:
public String printlnfo()
{
return "age:"+age+" name:"+name+" sex:"+sex+" age:"+age;
}
然后在mian中
public static void main(String []age)
{
Student s=new Student(1,"baidu","GG",20);
System.out.println(s.printlnfo());
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2011-04-05
展开全部
public class student
{
private int no;
private string name;
private string sex;
private int age;
public student(){
}
}
{
private int no;
private string name;
private string sex;
private int age;
public student(){
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询