zhangnana666777
2017-04-05 07:56
采纳率: 18.2%
浏览 2.9k
已采纳

新手 java 在构造函数中给类中的变量赋值问题

package complex_number;
import java.util.*;

public class ComplexNumber {

public static void main(String[] args){
    java.util.Scanner scanner = new java.util.Scanner(System.in);
    float m_dRealPart;
    float m_dImaginPart;

    System.out.println("Please enter the real and imaginary parts of the plural:");
    m_dRealPart=scanner.nextFloat();
    m_dImaginPart=scanner.nextFloat();
    System.out.println("\n");
    System.out.println("What kind of operation do you want to do? (1 Plus, 2 minus, 3 multiply, 4 divide)");
}

/*构造函数,ComplexNumber,将实部和虚部置0*/
public ComplexNumber(){
m_dRealPart=0;
m_dImaginPart=0;
}

    请问在构造函数的时候为什么会错?

3条回答 默认 最新

相关推荐 更多相似问题