Topics Index


If you need explanation Read this topic

If you need Answer Take test on this topic

What will be the output of the following program?
class White {
    White() {
        System.out.print("white is ");
class Purple extends White {
    Purple(String color) {
public class Black extends Purple {
    Black() {
        super("beautiful" + ",");
    public static void main(String[] a) {
        new Black();
        new Purple("nice");

A. white is beautiful ,nice
B. white is nice
C. white is beautiful,white is nice
D. white is nice
E. Compilation Error or Runtime error
Topic: Unknown

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.

ans is c ...
first white is printed then beauriful..
then constructor pf black is called in which white conatructor prints white and purple class const prints nice

Posted by Mânïshå Mùlchåndânï    2014-07-29 09:26:56

ans E, the Black() is a public class ,so it lesads to compilation error.

Posted by Damu Surya    2014-07-29 09:32:09

c,when black()  is executed,first its super consructor is executed ,its super class consists one its own super class white,so first white constructor then purle constructor is second case,since prple extends white,super class constructor (white) will be executed then purple class constructer

Posted by Prabhakar Reddy    2014-07-29 10:06:11

Option C. is the correct answer

Posted by Jagadish Panduri    2014-07-29 10:12:34


Posted by Samyuktha Reddy    2014-07-29 10:12:53

even though Purple is not calling its superclass constructor explicitly java will automatically call no argument constructor of superclass every time subclass object is created

Posted by Tushar Ghude    2014-07-29 14:32:17

Congratulations Mânïshå Mùlchåndânï. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-07-30 04:20:49

© meritcampus 2019

All Rights Reserved.

Open In App