java实例化构造方法_JAVA 实例化对象构造方法的流程是怎么走的?

问:实例化对象构造方法的流程是怎么走的?我输入DrawIconicon=newDrawIcon(800,800);这段程序不是应该只会自动调用DrawIcon的构造方法吗?为何还会实现其他方法?为何输出结果是42312...

问:实例化对象构造方法的流程是怎么走的?

我输入DrawIcon icon = new DrawIcon(800,800);

这段程序不是应该只会自动调用DrawIcon的构造方法吗?

为何还会实现其他方法?

为何输出结果是

4231231

package gui;

import java.awt.*;

import javax.swing.*;

public class DrawIcon implements Icon{

private int widht;

private int height;

public void paintIcon(Component c, Graphics g, int x, int y) {

// TODO 自动生成的方法存根

g.fillOval(x, y, widht, height);

System.out.print(1);

}

public int getIconWidth() {

// TODO 自动生成的方法存根

System.out.print(2);

return this.widht;

}

public int getIconHeight() {

// TODO 自动生成的方法存根

System.out.print(3);

return this.height;

}

public DrawIcon(int widht,int height){

// TODO 自动生成的方法存根

this.height=height;

this.widht=widht;

System.out.print(4);

}

public static void main(String[] args) {

DrawIcon icon = new DrawIcon(800,800);

}

}

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值