Menu
Question Index
...

What will be the output of the following program?

class Note {
    String n1 = "n1";
    String n2 = "n2";
}
public class Book extends Note {
    String n1 = "n3";
    public static void main(String args[]) {
        Book n = new Book();
        Note b = n;
        System.out.println(n.n1 + n.n2 + b.n1 + b.n2);
    }
}


n1n2n1n2
n3n2n3n2
n3n2n1n2
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Static and Non Static Variables - Static and Non Static Methods

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App