Open In App
Related Articles

Java | Inheritance | Question 9

Improve Article
Save Article
Like Article

final class Complex {
    private final double re;
    private final double im;
    public Complex(double re, double im) { = re; = 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);


Complex number is (10.0 + 15.0i)

(B) Compiler Error

Complex number is SOME_GARBAGE


Complex number is Complex@8e2fb5

Here 8e2fb5 is hash code of c

Answer: (A)

Explanation: See

Quiz of this Question

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 28 Jun, 2021
Like Article
Save Article
Similar Reads