编程题
1写出一个类People,并由该类做基类派生出子类Employee和Teacher。其中People类具有name、age两个保护成员变量,分别为String类型、整型,且具有公有的getAge成员函数,用于返回age变量的值。Employee类具有保护成员变量empno,Teacher类有teano和zc成员变量。2编写一个输出"Hello World!"的程序,用两种方式实现(Application、Applet)。
编程题
1写出一个类People,并由该类做基类派生出子类Employee和Teacher。其中People类具有name、age两个保护成员变量,分别为String类型、整型,且具有公有的getAge成员函数,用于返回age变量的值。Employee类具有保护成员变量empno,Teacher类有teano和zc成员变量。1
写出一个类People,
public class People{
protected String name;
protected int age;
public int getAge() {
return age;
}
}
class Employee extends People{
protected String empno;
}
class Teacher extends People{
protected String teano;
protected String zc;
}
2
application程序
public class a
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}
applet程序
public class b extends java.applet.Applet
{
public paint(java.awt.Graphics g)
{
g.outstring("Hello World!",10,10);
}
}
第一题:
public class People { private String name; private int age; 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; }
} class Employee extends People{ private int empno;
public Employee(int empno) { super(); this.empno = empno; } } class Teacher extends People{ private int teano; private String zc; public int getTeano() { return teano; } public void setTeano(int teano) { this.teano = teano; } public String getZc() { return zc; } public void setZc(String zc) { this.zc = zc; } }