代码: Student 成员变量:学号,姓名,年龄
构造方法:无参,带参
成员方法:
getXxx()/setXxx()
学习的方法。
Teacher
成员变量:员工编号,姓名,年龄
构造方法:无参,带参
成员方法:
getXxx()/setXxx()
教学的方法。
*/
class Person{
private String name;
private int age;
public Person(){}
public Person(String name,int age){
this.name = name;
this.age = age;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setAge(int age){
this.age = age;
}
public int getAge(){
return age;
}
}
class Teacher extends Person{
//private String name;
//private int age;
private String tid;
public Teacher(){}
public Teacher(String name,int age,String tid){
super(name,age);
this.tid = tid;
}
public void setTid(String tid){
this.tid = tid;
}
public String getTid(){
return tid;
}
public void teach(){
System.out.println("教学方法");
}
}
class Student extends Person {
//private String name;
//private int age;
private String sid;
public Student(){}
public Student(String name,int age,String sid){
super(name,age);
this.sid = sid;
}
public void setSid(String sid){
this.sid = sid;
}
public String getSid(){
return sid;
}
public void study(){
System.out.println("学习方法");
}
}
class PersonTest{
public static void main(String[] args){
Teacher t = new Teacher();
t.setName("刘意");
t.setAge(30);
t.setTid("0725号");
System.out.println(t.getName()+"---"+t.getAge()+"---"+t.getTid());
}
}
编译没问题,可是执行报错:
Exception in thread "main" java.lang.NoClassDefFoundError: personTest (wrong nam
e: PersonTest)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:800)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:14
2)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)
at java.net.URLClassLoader.access$100(URLClassLoader.java:71)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)
|
|