R

Ram Sharma • 193.86K Points
Coach

Q. Predict the output of following Java program 

Code:
final class Complex {
 
    private final double re;
    private final double im;
 
    public Complex(double re, double im) {
        this.re = re;
        this.im = im;
    }
 
    public String toString() {
        return "(" + re + " + " + im + "i)";
    }
}
 
class Main {
  public static void main(String args[])
  {
       Complex c = new Complex(10, 15);
       System.out.println("Complex number is " + c);
  }         
}
  • (A) Complex number is (10.0 + 15.0i)
  • (B) Complex number is SOME_GARBAGE
  • (C) Complex number is Complex@8e2fb5
  • (D) Compiler Error
  • Correct Answer - Option(A)
  • Views: 3783
  • Filed under category JAVA

No solution found for this question.
Add Solution and get +2 points.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.


Question analytics