Java作业求帮助 题一: 编写一个Java程序,在程序中定义一个PersonA类,定义 java语言1. 编写程序,定义一个Person类,属性包括...

Java\u4f5c\u4e1a\u6c42\u5e2e\u52a9 \u7f16\u5199\u4e00\u4e2aJava\u7a0b\u5e8f\uff0c\u5728\u7a0b\u5e8f\u4e2d\u5b9a\u4e49\u4e00\u4e2aPersonB\u7c7b\uff0c\u5b9a\u4e49\u4e00\u4e2aP

class PersonB
{
String name ;
int age;
public PersonB()
{
System.out.println("PersonB()\u88ab\u8c03\u7528");
}
public PersonB(String newName)
{
name = newName;
System.out.println("PersonB(String newName)\u88ab\u8c03\u7528");
}
public void introduce( )
{
System.out.println("\u6211\u662f"+name+",\u4eca\u5e74"+age+"\u5c81");
}
}
class StudentB extends PersonB
{
//\u3010\u4ee3\u78011\u3011 //\u521b\u5efa\u4e00\u4e2a\u53c2\u6570\u4e3a\u7a7a\u7684StudentB\u7c7b\u6784\u9020\u65b9\u6cd5\uff0c\u80fd\u663e\u793a\u201cStudentB()\u88ab\u8c03\u7528\u201d
public StudentB(){
System.out.println("StudentB()\u88ab\u8c03\u7528");
}
public StudentB(String newName,int newAge)
{
//\u3010\u4ee3\u78012\u3011 //\u8c03\u7528\u7236\u7c7b\u7684public PersonB(String newName)\u7c7b\u6784\u9020\u65b9\u6cd5\uff0c\u4f20\u5165newName\u53c2\u6570\uff0c\u63d0\u793a\u4f7f\u7528\u5173\u952e\u8bcdsuper\u8fdb\u884c\u8c03\u7528
super(newName);
//\u3010\u4ee3\u78013\u3011 //\u5c06newAge\u8d4b\u503c\u7ed9age\u5c5e\u6027
super.age = newAge;
}
}
class C2
{
public static void main(String []args)
{
StudentB s1 = new StudentB();
StudentB s2 = new StudentB("\u5f20\u4e09",19);
//\u3010\u4ee3\u78014\u3011 //\u8c03\u7528s2\u7684 introduce\u65b9\u6cd5
s2.introduce();
}
}


\u7eaf\u624b\u6253\uff0c\u91c7\u7eb3\u91c7\u7eb3\uff01\uff01\uff01\uff01\uff01\uff01\uff01\uff0111

class Person{
private String name, address;
private int age;
//get / set methods
}
~
~
~

代码1:extends PersonA

代码2:s1.setName("张三");
代码3:s1.setDepartment("计算机系");
代码4:System.out.println(s1.getName());
代码5:System.out.println(s1.getDepartment());

注意,后四句最后的分号别落下了

  1. extends PersonA

  2. s1.setName("张三");

  3. s1.setDepartment("计算机系");

  4. System.out.println(s1.getName());

  5. System.out.println(s1.getDepartment());



扩展阅读:搜答案神器 ... java视频课 ... 答题神器一扫就出答案 ... java基础面试题2024 ... java api在线帮助文档 ... javascript入门 ... 扫一扫题目出答案 ... jdkapi1.8中文版在线 ... 免费的html大作业网站 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网