Menu
Topics Index
...
`

Class inside other class


If you need explanation Read this topic

If you need Answer Take test on this topic

Class inside other class
What will be the output of the following program?
class Point {
    final int x, y;
    final String name;
    Point(int X, int Y) {
        x = X;
        y = Y;
        name = makeN();
    }
    String makeN() {
        return "[" + x + "," + y + "]";
    }
    public String toString() {
        return name;
    }
}
public class Point2 extends Point {
    final String c;
    Point2(int x, int y, String C) {
        super(x, y);
        c = C;
    }
    String makeN() {
        return super.makeN() + ":" + c;
    }
    public static void main(String... a) {
        System.out.println(new Point2(1, 3, "Blue"));
    }
}

A. [1,3]:Blue
B. [2,4]:Blue
C. [3,1]:Blue
D. Some other output
E. Compilation Error or Runtime Error
Topic: final Keyword In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

A is ans..as v r passing parametrs to constrctr of Point2 and c val is null..and again parametrs r passd to super class ie;point .

Posted by Shabaaz Shaikz    2014-07-30 12:42:15


Ans is d here [1,3] nul wil print in toString v are not adding c value

Posted by Uday Kumar    2014-07-30 13:20:28


Ans is D..some other output i.e.,we are printing only x,y values and not string the method toString only returns but it does not print..So the output is [1,3]

Posted by Badam Swathi    2014-07-30 14:21:28


Congratulations Uday Kumar. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-07-31 04:36:48


© meritcampus 2019

All Rights Reserved.

Open In App