创建一个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;
}
全部评论

相关推荐

不入算法余生悔:大二开始实习,本科三年经验,再考个研,到研二正好是五年经验
点赞 评论 收藏
分享
09-29 13:47
门头沟学院 Java
#腾讯 #阿里 #字节
投递小米集团等公司10个岗位 >
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务