Menu
Topics Index
...
`

Maggi and Noodles2960


If you need explanation Read this topic

If you need Answer Take test on this topic

Maggi and Noodles2960
What will be the output of the following program?
class FoodItems
{
    public static void main(String s[])
    {
        Noodles eat = new Noodles();
        eat.print();
    }
}

class Maggi
{
    private int spoon = 3;
    private int sticks = 4;
}

class Noodles extends Maggi
{
    private int powder = 1;
    private int fire = 2;

    void print()
    {
        System.out.println(powder + " " + fire + " " + sticks + " " + spoon);
    }
}

A. 1 2 4 3
B. 1 2 4
C. Compilation Error
D. Runtime Error
Topic: Using private Keyword In Java For Access Control

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.

Compilation error
Reason sub class cannot extend the private class which are present in super class.
Error bcoz if we try to extended private value it will not execute the program..

Posted by Fuzail Ahmed    2014-12-16 05:20:56


This dose is now closed and the winners are Sai Ram,  for 'First Correct Comment', Sai Ram,  for 'Best Comment' and Sai Ram for the 'Popular Comment'. The 'lucky liker' is Fuzail Ahmed. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-12-17 06:53:00


© meritcampus 2019

All Rights Reserved.

Open In App