+ 2
Can you please share the solution for the abstract classes practice in java?
Hello everyone! I think I found the solution but the console is declaring it incorrect. Can you please share the solution if you have?
22 Antworten
+ 5
You are missing the semi-colon ";" after your print statement ("Kill the enemy king.")
+ 5
Can we see your code first?
Copy the task, add that here. Then, copy your code answer, create a code in the code playground, paste your code there, save it and attach it here.
+ 3
Share your tried code with task description here..., if you want to know what went wrong in your code.
Sharing solutions not helps you in learning...
+ 3
Show your attempt
+ 2
Omg! I read this code more than 10 times but did not see this mistake. Thank you so much dear Ausgrindtube !
+ 2
Yes. Missing semicolon.
And you never using getName() method. .. !?!
Is it used in next lesson?!?!
Fine. Always share code link instead of copy paste code next time so it will easy you to find mistakes...
+ 2
Glad I could help Saidazim, it happens to us all .
Happy coding!
+ 2
Thanks all of you!
+ 2
Ahh! Now I see it. King should be lower-case king.
+ 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 {
abstract String getName();
abstract void play();
}
class Monopoly extends Game {
//give "Monopoly" name to game
String getName() {
return "Monopoly";
}
// play method should print "Buy all property."
void play() {
System.out.println("Buy all property.");
}
}
class Chess extends Game {
//give "Chess" name to game
String getName() {
return "Chess";
}
// play method should print "Kill the enemy king."
void play() {
System.out.println("Kill the enemy king.")
}
}
class Battleships extends Game {
//give "Battleships" name to game
String getName() {
return "Battleships" ;
}
+ 1
+ 1
It looks fine and works for me. Did you copy and paste the text in the print statements? Maybe remove the spaces and full stops and add them in manually, see if that changes anything.
Also check the task and make sure it matches everything exactly (which it looks like it does)
+ 1
Thank you
+ 1
Happy I could help you out! Enjoy your coding!
+ 1
That's the working code Ausgrindtube thanks for spotting the error earlier about "king" being in uppercase yet it was supposed to be in lower case.
0
// play method should print "Sink all ships."
void play() {
System.out.println("Sink all ships.");
}
}
0
Hello, am also having issue running this code. Can anyone help.
public 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 {
abstract String getName();
abstract void play();
}
class Monopoly extends Game {
//give "Monopoly" name to game
public String getName() {
return "Monopoly";
}
// 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 String getName() {
return "Chess";
}
// play method should print "Kill the enemy king."
public void play() {
System.out.println("Kill the enemy King.");
}
}
class Battleships extends Game {
//give "Battleships" name to game
public String getName() {
return "Battleships";
}
// play method should print "Sink all ships."
public void play() {
System.out.println("Sink all ships.");
}
}
0
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 {
abstract String getName();
abstract void play();
}
class Monopoly extends Game {
//give "Monopoly" name to game
String getName() {
return "Monopoly";
}
// play method should print "Buy all property."
void play() {
System.out.println("Buy all property.");
}
}
class Chess extends Game {
//give "Chess" name to game
String getName() {
return "Chess";
}
// play method should print "Kill the enemy king."
void play() {
System.out.println("Kill the enemy King.");
}
}
class Battleships extends Game {
//give "Battleships" name to game
String getName() {
return "Battleships";
}
// play method should pr
0
I write all code manually the ones that were missing.
0
Ausgrindtube I even copied and pasted the code in both ChatGBT and an online java compiler to see whether errors exists, but none. They all ran the code without any errors returned.