网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 生活知识 知识问答

构造方法的使用

时间:2026-02-14 17:13:59

1、打开电脑上的eclipse软件,配置好jdk的。

构造方法的使用

2、点击左上角的file,点击new,点击Javaproject。

构造方法的使用

3、新建一个class文件,自己取名字,勾引main选项,自动调用main方法

构造方法的使用

4、输入代码

class Student {

static {

System.out.println("Student 静态代码块");

}

{

System.out.println("Student 构造代码块");

}

public Student() {

System.out.println("Student 构造方法");

}

}

class Animal {

static {

System.out.println("Demo2_Student静态代码块");

}

public static void main(String[] args) {

System.out.println("我是main方法");

Student s1 = new Student();

Student s2 = new Student();

}

}

构造方法的使用

5、控制台会出现

Demo2_Student静态代码块

我是main方法

Student 静态代码块

Student 构造代码块

Student 构造方法

Student 构造代码块

Student 构造方法

构造方法的使用

© 2026 智德知识库
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com