class Person{
private String name;
private int 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 Student extends Person{
private String school;
public void setSchool(String school){
this.school=school;
}
public String getSchool(){
return school;
}
}
public class TestPerson{
public static void main (String arg[]){
Student student=new Student();
Student.setName("jim");
Student.setAge(78);
Student.setSchool("home");
System.out.println(student.getName());
System.out.println(student.getAge());
System.out.println(student.getSchool());
}
}
private String name;
private int 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 Student extends Person{
private String school;
public void setSchool(String school){
this.school=school;
}
public String getSchool(){
return school;
}
}
public class TestPerson{
public static void main (String arg[]){
Student student=new Student();
Student.setName("jim");
Student.setAge(78);
Student.setSchool("home");
System.out.println(student.getName());
System.out.println(student.getAge());
System.out.println(student.getSchool());
}
}
解决方案 »
- 简单数据库中更新数据出错 牛人们看下啊
- 在线求简单sql语句如何写?。用户登录。会的给看下!谢谢了
- Java调试平台
- 求助:Exception in thread "main" java.lang.NullPointerException at myjava.main(myjava:12)
- 不用集成环境,在dos环境下怎样运行编好的java 文件
- 有关《Thingking in Java Second Edition》
- SCJP
- 请教Swing 与AWT的关系?
- JAVA开发过那些应用程序?好象没有???
- 见笑了,用jbuilder编译的class,如何运行它
- 请问下做过项目的高人:桌面系统的疑问?
- 什么时候加void?public void Info(){}和double info(){}一个加了void一个冒?为什么?不都是打印出东西?
Student.setName("jim");
Student.setAge(78);
Student.setSchool("home"); to
student.setName("jim");
student.setAge(78);
student.setSchool("home");
private static String name;
private static int age;
public static void setName(String n){
name=n;
}
public String getName(){
return name; }
public static void setAge(int a){
age=a; }
public int getAge(){
return age;
}
}
class Student extends Person{
private static String school;
public static void setSchool(String s){
school=s;
}
public String getSchool(){
return school;
} }
public class TestPerson{
public static void main (String arg[]){
Student student=new Student();
Student.setName("jim");
Student.setAge(78);
Student.setSchool("home");
System.out.println(student.getName());
System.out.println(student.getAge());
System.out.println(student.getSchool());
}
}
private static String name;
private static int age;
public static void setName(String n){
name=n;
}
public String getName(){
return name; }
public static void setAge(int a){
age=a; }
public int getAge(){
return age;
}
}
class Student extends Person{
private static String school;
public static void setSchool(String s){
school=s;
}
public String getSchool(){
return school;
} }
public class TestPerson{
public static void main (String arg[]){
Student student=new Student();
Student.setName("jim");
Student.setAge(78);
Student.setSchool("home");
System.out.println(student.getName());
System.out.println(student.getAge());
System.out.println(student.getSchool());
}
}
private static String name;
private static int age;
public static void setName(String n){
name=n;
}
public String getName(){
return name; }
public static void setAge(int a){
age=a; }
public int getAge(){
return age;
}
}
class Student extends Person{
private static String school;
public static void setSchool(String s){
school=s;
}
public String getSchool(){
return school;
} }
public class TestPerson{
public static void main (String arg[]){
Student student=new Student();
Student.setName("jim");
Student.setAge(78);
Student.setSchool("home");
System.out.println(student.getName());
System.out.println(student.getAge());
System.out.println(student.getSchool());
}
}
public static void main (String arg[]){
Student student=new Student();
Student.setName("jim");
Student.setAge(78);
Student.setSchool("home");
System.out.println(student.getName());
System.out.println(student.getAge());
System.out.println(student.getSchool());
}
}student.setName("jim");
student.setAge(78);
student.setSchool("home"); 用定义的对象名student而不是class名
public class TestPerson {
private String aaaa;
public static void main (String arg[]){ Student student;
TestPerson tp=new TestPerson();//实例化TestPerson类,以用来调用它里面的内部类Studnet
student=tp.new Student();//因为Studnet是TestPerson的一个内部类,想实例化一个Student对象你必须在实例化好的外部类中调用. student.setName("jim");
student.setAge(78);
student.setSchool("home");
System.out.println(student.getName());
System.out.println(student.getAge());
System.out.println(student.getSchool());
} class Person {
private String name; private int 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 Student extends Person {
private String school; public void setSchool(String school) {
this.school = school;
} public String getSchool() {
return school;
} }}你试一下看看是出现结果了.
TestPerson tp=new TestPerson();//实例化TestPerson类,以用来调用它里面的内部类Studnet
student=tp.new Student();//因为Studnet是TestPerson的一个内部类,想实例化一个Student对象你必须在实例化好的外部类中调用.
student.setName("jim");
student.setAge(78);
student.setSchool("home");
System.out.println(student.getName());
System.out.println(student.getAge());
System.out.println(student.getSchool());
} class Person {
private String name; private int 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 Student extends Person {
private String school; public void setSchool(String school) {
this.school = school;
} public String getSchool() {
return school;
} } } 刚才红色字后面的在下一行,有些错位.
不好意思.
呵呵@@@@
private String name;
private int 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 Student extends Person {
private String school; public void setSchool(String school) {
this.school = school;
} public String getSchool() {
return school;
}}public class TestPerson {
public static void main(String arg[]) {
Student student = new Student();
student.setName("jim"); // 修改Student为student,由于Student不是static类型的,所以不能直接调用类中的方法,因此会编译错误
student.setAge(78); // 在前一行实例化了一个Student对象,因此,应该对这个对象进行赋值、取值操作。
student.setSchool("home");
System.out.println(student.getName());
System.out.println(student.getAge());
System.out.println(student.getSchool());
}
}
this.name=name;
}
public void setAge(int age){
this.age=age; }
//以上两个方法使用错误,换成构造函数去实现他们
public Person(String name,int age){
this.name = name;
this.age = age;}
Person p = new Person("mike",11);//建立对象把属性传给构造函数执行初始化操作,构造函数就是用来初始化对象的
public void setSchool(String school){
this.school=school;
} public Student(String name,int age,String school){//第二个类的构造函数必须带上他父类的成员然后加上自己类的成员super(name,age);//super()方法自动调用父类中的构造函数以实现初始化操作
this.school = school;
}Student stu = new Student("mike",11,"bgedu");//建立对象