我想当你从另一个对象扩展一个对象时,那个对象就会接收到所有的变量,这些变量的定义以及那个对象的方法。所以,当我有这样的代码“扩展”是否也扩展变量?
import javax.swing.*;
import java.awt.*;
public abstract class Object extends JComponent{
private int xpos;
private int ypos;
private int height;
private int width;
private double rotate;
private Rectangle rect;
public Object(int p1, int p2, int w, int h, double r){
this.xpos = p1;
this.ypos = p2;
this.width = w;
this.height = h;
this.rotate = r;
rect = new Rectangle(xpos, ypos, width, height);
}
}
与原始对象,然后另一个对象是这样的:
import javax.swing.*;
import java.awt.*;
public class Block extends Object{
public Block(int p1, int p2, int p3, int p4, double r) {
super(p1, p2, p3, p4, r);
}
public void paintComponent(Graphics g){
Graphics2D gd = (Graphics2D) g;
gd.setColor(Color.BLUE);
gd.draw(rect);
}
}
为什么不矩形“矩形”正在扩大了吗?在java中我很新,所以请继续阅读XD
_为什么不是矩形“矩形”被扩展了?_你认为它在哪里? –
你为什么重新定义'Object'类?你知道这会给多个问题吗? –
为什么?有没有一个对象类?如果有我不知道它 – MagnusCaligo