Skip to content

Instantly share code, notes, and snippets.

@goldcode88
Last active April 2, 2017 02:15
Show Gist options
  • Select an option

  • Save goldcode88/5c470bc9a299c2a7a7a8d8433d16dafd to your computer and use it in GitHub Desktop.

Select an option

Save goldcode88/5c470bc9a299c2a7a7a8d8433d16dafd to your computer and use it in GitHub Desktop.
变量初始化例子
class Complex {
private double re, im;
//public int a,b,c=null; //fault
public int a,b,c; //correct
public String name,value=null;//correct
public Complex(double re, double im) {
this.re = re;
this.im = im;
a = 1;
b = 2;
c = 3;
name = "abc";
value = "def";
}
/* Returns the string representation of this Complex number.
The format of string is "Re + iIm" where Re is real part
and Im is imagenary part.*/
@Override
public String toString() {
return String.format(re + " + i" + im);
}
}
// Driver class to test the Complex clas
class Complex_test2 {
public static void main(String[] args) {
Complex c1 = new Complex(10, 15);
System.out.println(c1);
System.out.println(c1.a);
System.out.println(c1.name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment