Menu
Question Index
...

What will be the output of the following program?

class Base {
    public String name = "Base";
}
class Derived extends Base {
    private final String name = "Derived";
    public String getName() {
        return name;
    }
}
public class Details {
    public static void main(String[] args) {
        System.out.println(new Derived().getName());
        System.out.println(new Derived().name);
    }
}


Derived
Base
Derived
Derived
Derived
Base
Derived
Base
Derived
Derived
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: final Keyword 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