1 样题1.写出一个类People,并由该类做基类派生出子类Employee和Teacher。其中People类具有name、age 两个保护成员变量,分别为 String 类型、整型,且具有公有的 getAge 成员函数,用于返回 age 变量的值。Employee类具有保护成员变量empno,Teacher类有teano 和zc 成员变量。 答: 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.编写一个输出"Hello World",用两种方式实现(Application、Applet)。 答: Application: public class Hello { public static void main(String[] args) { System.out.println("Hello World"); } } Applet: import java.awt.*; import java.applet.*; public class HelloA extends Applet{ public void paint(Graphics g) { g.drawString("Hello World",50,25); } } 样题3.编写一个输出applet 实现界面,并实现在第一文本框中输入一个数后,按"求绝对值"按钮在第二个文本框中显示该数的绝对值,按"退出"按钮中断程序运行。 答: Import java.awt.*;import java.awt.event.*;import java.lang.Math; public class Abs implements ActionListener{ Frame f; TextField tf1,tf2; Button b1,b2; public void display(){ f=new Frame("求绝对值例子"); f.setSize(220,150); f.setLocation(320,240); f.setBackground(Color.lightGray); f.setLayout(new FlowLayout(FlowLayout.LEFT)); tf1=new TextField(10); tf1.setEditable(true); tf2=new TextField(10); tf2.setEditable(false); f.add(tf1); f.add(tf2); b1=new Button("求绝对值"); b2=new Button("退出"); f.add(b1); f.add(b2); b1.addActionListener(this); b2.addActionListener(this); f.addWindowListener(new WinClose()); f.setVisible(true); } public void actionPerformed(ActionEvent e){ if(e.getSource()==b1) { int value=(new Integer(tf1.getText())).intValue(); tf2.setText(Integer.toString(Math.abs(value))); } else { if(e.getSource()==b2) { 2 System.exit(0); } } } public...