
package Note;
public class Demo {
//属性
int a;
static int sa;
//方法
public void dynamic(){
System.out.println("----b");
//{}这个就是普通块,在方法中定义
{
System.out.println("这是普通块");
int num = 10;
System.out.println(num);
}
//System.out.println(num);
}
public static void state(){
System.out.println("-----qq");
}
//方法外的块就是,构造块
{
System.out.println("这是构造块---");
}
//构造方法
public Demo(int a){
this.a = a;
}
public Demo(){
System.out.println("这是个空构造器");
}
//代码块
static {
System.out.println("这是静态块");
}
//随着类的加载而加载,所以不用输出任何东西便可执行出"这是静态块",这句话
public static void main(String[] args) {
//创建对象
Demo d = new Demo();
d.dynamic();
Demo d1 = new Demo();
d1.dynamic();
}
}
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)