Accenture Accenture Primer Practice Question
Predict the output startprogram class Product { String productName; } class Mobile extends Product { String mobileName; void display() { super.productName = mobileName + “Brand New !”; System.out.println(mobileName +” “ + productName); } } class Main { public Static void main(String args[]) { Mobile obj = new Mobile(); obj.productName=”1”; obj.mobileName=”2”; obj.display(); } } endprogramAnswer options
A
2 2Brand New !
B
1 2Brand New !
C
1 1Brand New !
D
Brand New !
Correct answer: 2 2Brand New !
Explanation
In display(): super.productName = mobileName + 'Brand New !' = '2Brand New !'. Then System.out.println(mobileName + ' ' + productName) prints '2 2Brand New !' because productName now holds '2Brand New !'.