车
package Test;
public class Test_car {
public static void main(String[] args) {
Car myCar=new Car();
myCar.setSeat(5);
myCar.getSeat();
myCar.start();
}
}
class Veihicle{
private int speed;
public void start() {
System.out.println("启动");
}
public void speedUp() {
System.out.println("减速");
}
public void speedDown() {
System.out.println("减速");
}
public void stop() {
System.out.println("停车");
}
}
class Car extends Veihicle{
private int seat;
public void setSeat(int seat) {
this.seat = seat;
}
public void getSeat() {
System.out.println(seat);
}
}
JFrame的继承
package TestMp3;
import javax.swing.*;
import java.awt.FlowLayout;
public class TestMp3 {
public static void main(String[] args) {
MP3Frame mp3=new MP3Frame();
mp3.setTitle("我的播放器");
mp3.setLayout(new FlowLayout());
mp3.add(new JButton("播放器"));
mp3.add(new JButton("暂停"));
mp3.add(new JButton("切歌"));
mp3.setSize(300,150);
mp3.setVisible(true);
}
}
class MP3Frame extends JFrame{
}