Java作业求帮助 编写一个Java程序,在程序中定义一个PersonB类,定义一个P Java作业求帮助 编写一个Java程序,在程序中定义一个A...

Java\u4f5c\u4e1a\u6c42\u5e2e\u52a9 \u9898\u4e00: \u7f16\u5199\u4e00\u4e2aJava\u7a0b\u5e8f\uff0c\u5728\u7a0b\u5e8f\u4e2d\u5b9a\u4e49\u4e00\u4e2aPersonA\u7c7b\uff0c\u5b9a\u4e49

\u4ee3\u78011\uff1aextends PersonA

\u4ee3\u78012\uff1as1.setName("\u5f20\u4e09");
\u4ee3\u78013\uff1as1.setDepartment("\u8ba1\u7b97\u673a\u7cfb");
\u4ee3\u78014\uff1aSystem.out.println(s1.getName());
\u4ee3\u78015\uff1aSystem.out.println(s1.getDepartment());

\u6ce8\u610f\uff0c\u540e\u56db\u53e5\u6700\u540e\u7684\u5206\u53f7\u522b\u843d\u4e0b\u4e86

class Bird extends Animal
{
void breathe()
{
System.out.println(\u201cbird breathe\u201d);
}
}

class Fish extends Animal
{
void breathe()
{
System.out.println(\u201cfish breathe\u201d);
}
}

class PersonB
{
String name ;
int age;
public PersonB()
{
System.out.println("PersonB()被调用");
}
public PersonB(String newName)
{
name = newName;
System.out.println("PersonB(String newName)被调用");
}
public void introduce( )
{
System.out.println("我是"+name+",今年"+age+"岁");
}
}
class StudentB extends PersonB
{
// 【代码1】 //创建一个参数为空的StudentB类构造方法,能显示“StudentB() 被调用”
public StudentB(){
System.out.println("StudentB() 被调用");
}
public StudentB(String newName,int newAge)
{
// 【代码2】 //调用父类的public PersonB(String newName)类构造方法,传入newName参数,提示使用关键词super进行调用
super(newName);
// 【代码3】 //将newAge赋值给age属性
super.age = newAge;
}
}
class C2
{
public static void main(String []args)
{
StudentB s1 = new StudentB();
StudentB s2 = new StudentB("张三",19);
// 【代码4】 //调用s2的 introduce方法
s2.introduce();
}
}

纯手打,采纳采纳!!!!!!!!11

class StudentB extends PersonB
{
//创建一个参数为空的StudentB类构造方法,能显示“StudentB()被调用”
public StudenB(){
System.out.println("StudentB()被调用");

}
public StudentB(String newName,int newAge)
{
//调用父类的public PersonB(String newName)类构造方法,传
//入newName参数,提示使用关键词super进行调用
super(newName);
//将newAge赋值给age属性
age=newAge;
}
}
class C2
{
public static void main(String []args)
{
StudentB s1 = new StudentB();
StudentB s2 = new StudentB(“张三”,19);
//调用s2的 introduce方法
s2.introduce( );
}
}

扩展阅读:java api在线帮助文档 ... java帮助文档手机版 ... 百度作业帮 在线 品牌 ... javascript入门 ... java帮助文档中文版 ... java作业员工管理系统 ... java作业搜题 ... 如何编写一个简单的java ... java帮助文档怎么打开 ...

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