Menu
Topics Index
...
`

Abstract Class


If you need explanation Read this topic

If you need Answer Take test on this topic

Abstract Class
What will be the output of the following program?
public abstract class AbstractTest
{
    public int getNum()
    {
        return 45;
    }

    public abstract class Bar
    {
        public int getNum()
        {
            return 38;
        }
    }

    public static void main (String [] args)
    {
        AbstractTest t = new AbstractTest()
        {
            public int getNum()
            {
                return 22;
            }
        };

        AbstractTest.Bar f = t.new Bar()
        {
            public int getNum()
            {
                return 57;
            }
        };
        System.out.println(f.getNum() + " " + t.getNum());
    }
}

A. 45 57
B. 45 38
C. 57 22
D. Compilation Error
E. Runtime Error
Topic: Rules For Abstract Methods and Abstract Classes

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. object f returns value 57 and object t returns 22. The initial values will be overridden and the new values for the corresponding methods will take effect.

Posted by Nikhil Sulibhavi    2014-08-12 12:37:02


C is ans..bcz  first using f objct we call getNum n 57 is prntd den t.getNum returns 22

Posted by Shabaaz Shaikz    2014-08-12 12:37:21


Answer is C 57 22 after creating objects t and f the first method called in println statement is by using f i.e f.getNum() which returns 57 and later t.getNum() is called to return 22 both are printed in this way

Posted by Sai Avinash    2014-08-12 12:38:07


ans is c..f.getname() wl return 57 n t.getnum wil return 22

Posted by Uday Kumar    2014-08-12 12:41:37


ANS IS D...
Error - At least one public class is required in main file

Posted by Mânïshå Mùlchåndânï    2014-08-12 12:41:53


Answer is D:      To run this program we need atleast one public class in the main file

Posted by Chandra Sekhar Reddy    2014-08-12 12:50:07


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

Posted by Merit Campus    2014-08-13 04:16:06


© meritcampus 2019

All Rights Reserved.

Open In App