仪器社区

测试类应该怎么加啊??

tjgykhulj 2018-11-24
/*要求新建一个PersonTest测试类,对person类进行测试*/ package com.soft.ght; public class Person拓展 { String name; int age; String address; char sex; int weight; public class PersonTest{ public static void main(String[] args... /*要求新建一个PersonTest测试类,对person类进行测试*/ package com.soft.ght; public class Person拓展 { String name; int age; String address; char sex; int weight; public class PersonTest{ public static void main(String[] args) { // TODO Auto-generated method stub Person p1=new Person();//声明并实例化Person类对象p1 Person p2=new Person();//声明并实例化Person类对象p2 //给p1赋值 p1.name="张三"; p1.age=25; p1.address ="济南"; p1.sex ='m'; p1.weight =100; //给p2赋值 p2.name ="李四"; p2.age =30; p2.address ="北京"; p2.sex ='w'; p2.weight =80; System.out.println("名字:"+p1.name +" ,年龄:"+p1.age +" ,家庭住址:"+p1.address +" ,性别:"+p1.sex +" ,体重:"+p1.weight ); System.out.println("名字:"+p2.name +" ,年龄:"+p2.age +" ,家庭住址:"+p2.address +" ,性别:"+p2.sex +" ,体重:"+p2.weight ); } }} 我是这么写的,可是编译的时候说我错了,非要把public class PersonTest{}改成public static class PersonTest{}或者把public static void main(String[] args) {}改成public void main(String[] args) {}才显示正确。错误提示是:The method main cannot be declared static; static methods can only be declared in a static or top level type 这是哪里出了问题?我要怎么改呢?
评论
全部评论
您可能感兴趣的社区主题
加载中...
发布 评论