Question
1- What is the output of the following program? Why? public class Player { private int lives; public Player() { lives = 0; } public
1- What is the output of the following program? Why?
public class Player { private int lives;
public Player() { lives = 0; }
public Player(int plives) { lives = plives; }
public void addLives() { lives++; }
public void display() { System.out.print(lives + " "); } }
public class SpecialPlayer extends Player {
public SpecialPlayer(int plives) {super(2*plives); } }
public class Main{ public static void main(String[]args){
Player player = new Player(5);
Player special = new SpecialPlayer(5);
player.display()
player.addLives();
player.display();
special.display();
special.addLives();
special.display();
}}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started