+ 3
What is the problem?
I cant solve the abstract class in Java Intermediate
8 Answers
+ 5
Don't share the code like this, please see this post
https://code.sololearn.com/Wek0V1MyIR2r/?ref=app
+ 5
Please post the task description as well. Not everyone has it in their memory.
// play method should print "Sink all ships."
public void play() {
System.out.println("Sink all battleships.");
If you look at the comment (line with //) and the print statement, you don't have the exact same wording i.e ships =/= battleships
+ 5
Pat it's ok, no problem
+ 4
Great you have the answer!
We all make those same mistakes.
Happy learning!
+ 3
Hahaha đ
That's the reason why I can't solve.
Thx very much !!!!
+ 3
Sorry Sakshi
I've posted my first question on sololearn. Next time I do it by the regular way đ
+ 1
class Main {
public static void main(String[] args) {
//do not touch this code
Monopoly monopoly = new Monopoly();
Chess chess = new Chess();
Battleships battleships = new Battleships();
monopoly.play();
chess.play();
battleships.play();
}
}
abstract class Game {
protected String name;
abstract String getName();
abstract void play();
}
class Monopoly extends Game {
//give "Monopoly" name to game
public void setName (String n){
this.name = n;
}
public String getName() {
return name;
}
// play method should print "Buy all property."
public void play() {
System.out.println("Buy all property.");
}
}
class Chess extends Game {
//give "Chess" name to game
public void setName (String n){
this.name = n;
}
public String getName() {
return name;
}
// play method should print "Kill the enemy king."
public void play() {
System.out.println("Kill the enemy
+ 1
}
}
class Battleships extends Game {
//give "Battleships" name to game
public void setName (String n){
this.name = n;
}
public String getName() {
return name;
}
// play method should print "Sink all ships."
public void play() {
System.out.println("Sink all battleships.");
}
}