Last active
April 2, 2017 02:15
-
-
Save goldcode88/5c470bc9a299c2a7a7a8d8433d16dafd to your computer and use it in GitHub Desktop.
变量初始化例子
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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