标签:this 姓名 his extends sleep return 调用 end generated
主类: package Szy02; public class Person { String name; int age; String sex; public Person(){ } public Person(String name,int age,String sex){ this.name=name; this.age=age; this.sex=sex; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } public String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } } 子类: package Szy02; public class Ren extends Person{ Ren(String name,int age,String sex){ super(name,age,sex); } public void r(){ System.out.println("姓名:"+this.name+"\t"+"年龄:"+this.age+"\t"+"性别:"+this.sex); } public void s(){ System.out.println("学java"); } public void sleep(){ System.out.println("晚上睡觉"); } } 测试类: package Szy02; public class Test04 { public static void main(String[] args) { // TODO Auto-generated method stub Ren r=new Ren("小王",22,"女"); r.r(); r.s(); r.sleep(); } }
标签:this 姓名 his extends sleep return 调用 end generated
原文地址:https://www.cnblogs.com/hankai2735/p/9066359.html