Menu
Question Index
...

What will be the output of the following program?

public class FoodItems {
    public static void main(String s[]) {
        Noodles eat = new Noodles();
        eat.print();
        Maggi mag = new Maggi();
        mag.print();
        System.out.println("~" + mag.sticks);
    }
}
class Maggi {
    private int spoon = 3;
    protected int sticks = 4;
    void print() {
        System.out.print("~" + spoon);
    }
}
class Noodles extends Maggi {
    private int powder = 1;
    protected int fire = 2;
    void print() {
        System.out.print(powder + "~" + fire + "~" + sticks);
    }
}


1~2~4~3~4
1~2~4~1~2~3~4
Compilation Error
Runtime Error

Doubts

Problems

Topic: Access Modifiers In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App