Skip to content

inheritance#5

Open
Dolev3 wants to merge 3 commits intomasterfrom
inheritance
Open

inheritance#5
Dolev3 wants to merge 3 commits intomasterfrom
inheritance

Conversation

@Dolev3
Copy link
Owner

@Dolev3 Dolev3 commented Aug 10, 2025

No description provided.

@@ -0,0 +1,16 @@
public class Spongebob extends Fish implements ProfessionalBasketBallPlayer{

public Spongebob(String name, int age, String favoriteFood) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you get a name if you don't use it?

public class CookSpongebob extends Spongebob{

private int age;
private String favoriteFood;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need this because fish already has this and this class inherits from fish

Comment on lines +7 to +10
p.playBasketBall();
}
else {
p.playBasketBall();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try not to copy code, call playBasketball only once

Comment on lines +24 to +25
if(fp instanceof ProfessionalBasketBallPlayer) {
basketBallPlayers[index] = (ProfessionalBasketBallPlayer)fp;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(fp instanceof ProfessionalBasketBallPlayer) {
basketBallPlayers[index] = (ProfessionalBasketBallPlayer)fp;
if(fp instanceof ProfessionalBasketBallPlayer basketballPlayer) {
basketBallPlayers[index] = basketballPlayer;

no need for casting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants