创建一个Student类,要求有

.创建一个Student类,要求有姓名,年纪,性别,是否单身属性,再创建一个静态方法,在静态方法中创建对象,给对象属性赋值,然后将对象返回给main方法

package work001;

public class Student001 {

    public static void main(String[] args) {
        student a = new student();
            System.out.println(a.name+a.age+a.sex+a.danshen);

    }
}
class student{
    String name;
    int age;
    String sex;
    boolean danshen;
public static String a(){
Student s =new Student();
a.name="tom";
a.age=18;
a.sex="man";
a.danshen=false;
return a;
}
全部评论

相关推荐

点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务