Initialization & Cleanup笔记

来源:互联网 发布:eve A族女性捏脸数据 编辑:程序博客网 时间:2024/06/05 22:52

public class Flower {
int petalCount = 0;
String s = "initial value";
Flower(int petals) {
petalCount = petals;
print("Constructor w/ int arg only, petalCount= "
+ petalCount);
}
Flower(String ss) {
print("Constructor w/ String arg only, s = " + ss);
s = ss;
}
Flower(String s, int petals) {
this(petals);//这句话只能放在开始位置
//! this(s); // Can’t call two!
this.s = s; // Another use of "this"
print("String & int args");
}
Flower() {
this("hi", 47);
print("default constructor (no args)");
}
void printPetalCount() {
//! this(11); // Not inside non-constructor!
print("petalCount = " + petalCount + " s = "+ s);
}
public static void main(String[] args) {
Flower x = new Flower();
x.printPetalCount();
}
}

 

=======================================

 

垃圾收集方法:mark and sweep , stop and copy

 

=======================================

 

public class MethodInit{
    //int j = g(i); // Illegal forward reference
    int i = 3;//f();
    int f() { return 11; }
    int g(int n) { return n * 10; }
    }

 

=======================================

 

public class OverloadingVarargs2 {
    static void f(float i, Character... args) {
        System.out.println("first");
    }

    static void f(Character... args) {
        System.out.print("second");
    }

    public static void main(String[] args) {
        f(1, 'a');
        // f('a', 'b');    //可选参数不能精确匹配,'a'会被提升为float
    }
}

原创粉丝点击