📄 superexam.java
字号:
package useSuper;
class Pen {
String color;
int length;
public Pen() { //默认构造函数,没有任何参数
}
Pen(String color) { //只有一个字符型参数color的构造函数
this.color = color;
}
Pen(int length) { //只有一个数值型参数length的构造函数
this.length = length;
}
Pen(String color, int length) { //有两个参数color和length的构造函数
this.color = color;
this.length = length;
}
void display() {
System.out.println("Color is " + color);
System.out.println("length is " + length);
}
}
class myPen extends Pen {
int weight;
public myPen() {
}
myPen(String color, int weight) {
super(color); //调用父类的构造函数Pen(String color)
this.weight = weight;
}
myPen(int length, int weight) {
super(length); //调用父类的构造函数Pen(int length)
this.weight = weight;
}
myPen(String color, int length, int weight) {
super(color, length); //调用父类的构造函数Pen(String color,int length)
this.weight = weight;
}
void display() {
super.display();
System.out.println("weight is " + weight);
}
}
public class superExam {
public static void main(String args[]) {
myPen p = new myPen("Blue",13,56);
p.display();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -