Topics Index

calling super class Constructor

If you need explanation Read this topic

If you need Answer Take test on this topic

calling super class Constructor
What will be the output of the following program?
class Mobile {
    static String str = "";
    protected Mobile() {
        str += "Mobile is : ";
class Airtel extends Mobile {
    private Airtel() {
        str += "Airtel";
public class Docomo extends Mobile {
    private Docomo() {
        str += "Docomo";
    public static void main(String args[]) {
        new Docomo();

A. Docomo
B. Mobile is : Airtel
C. Mobile is : Docomo
D. Some other output
E. Compilation Error or Runtime Error
Topic: Creating Static Methods In Java Using Static Keyword

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.


Posted by Frutti Tutti    2014-07-23 03:36:05


Posted by Khalid Ahmed    2014-07-23 03:44:58

Ans is C...object is created for class docomo and the string is appended with docomo and the output is Mobile is : Docomo

Posted by Badam Swathi    2014-07-23 04:03:03

blnc milta b h...???winnr to anounc  krte ni h ye log

Posted by Asma Mujtaba Khan    2014-07-23 05:02:54

E.compilation error since docomp class is public n mst be called with public class

Posted by Asma Mujtaba Khan    2014-07-23 05:56:09

1. string str is not private all classes can acess str + its a static field thr will be only one copy of str
2. Creating Subclass (Docomo) object calls its consturctor which will implicitly call constructor of its Superclass (Mobile)
3. we r not assigning new Docomo() to anything so instance will be lost but since str is static changes will be reflected (as Mobile and Docomo constructors change str)

Posted by Tushar Ghude    2014-07-23 07:20:03


Posted by Himani Mittal    2014-07-24 02:53:34

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

Posted by Merit Campus    2014-07-24 04:47:04


Posted by Pradeep Joshi    2014-07-24 14:06:36

© meritcampus 2019

All Rights Reserved.

Open In App