CodeGym /Java Course /Java Core /Practice with abstract classes | Level 2

Practice with abstract classes | Level 2

Java Core
Level 2 , Lesson 6
Available

"Hello, Amigo! You did so well on the previous exercises that I decided to find something a bit harder for you."

"Thanks, Diego. You're a real friend. I didn't expect that!!!"

3
Task
Java Core, level 2, lesson 6
Locked
Abstract Pet class
The Good Neighbor Farm takes in all pets, including outcasts and runaway convicts from all over the galaxy. But the farmers never know what kind of animals the intergalactic railroad will bring them next. To avoid any misunderstanding, create an abstract Pet class for the Good Neighbor Farm.
3
Task
Java Core, level 2, lesson 6
Locked
"Fix the code", part 1
This task is the start of a show where you'll be the star! Essentially, the main character is a skilled junior programmer who has to deal with code written by an inept coworker. In the end, the program compiles and everyone lives happily ever after.
3
Task
Java Core, level 2, lesson 6
Locked
"Fix the code", part 2
In this episode of "Fix the code", the young, but promising, programming intern must once again must wrestle with demons and... kittens. Aren't kittens the cutest? Or are they??? You could say this to Napoleon the cat breeder (if you dare!), but we need you to fix the code so that the program compiles.
3
Task
Java Core, level 2, lesson 6
Locked
Cows are animals too
During the intergalactic census, cows from Planet Earth weren't included in the unified animal register, because they were confused with a strikingly similar intelligent life form from Planet Mooing. Be a programmer! Correct this injustice! Make the Cow class inherit the Animal class and finish writing the Cow class's missing methods.
3
Task
Java Core, level 2, lesson 6
Locked
Cats should not be abstract!
Cats should not be abstract! Don't take my word for it - ask Schrodinger's cat. Its chilling story will convert any skeptic. But to not be bored, cats need their forever frenemies: dogs. So we will complete a task where two non-abstract Cat and Dog classes will inherit Pet, and then we'll write methods for them.
Comments (22)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Thomas Level 13, Scottsdale, United States
12 August 2024
Output: Cat name: Whiskers Dog name: Buddy Cat's child: com.codegym.task.task12.task1215.Solution$Cat@2893de87 Dog's child: com.codegym.task.task12.task1215.Solution$Dog@55ca8de8
Boat Level 40, Germany, Germany
24 April 2023
Fun fact related to the last task: Schrödinger's Cat is a thought experiment that Schrödinger devised to *criticise* Quantum Physics, not to explain them. And Einstein agreed with him. The idea that a cat could be both alive and dead at the same time was ridiculous to them and simply didn't line up with the world as we experience it.
Michael Amann Level 22, United States of America, United States
23 May 2022
Again with the cats!
ayhem bouabid Level 25, Tunis, Tunisia
10 January 2021
I think that having only easy tasks cannot be beneficial. IT PISSES ME OFF!!
Ricky Level 21, Norway
15 February 2022
Maybe so, but these are great to come back to if you need a refresher.
Pablo Saquilmer Level 32, Guatemala City, Guatemala
13 July 2020
Can someone explain to me what the heck is wrong here com/codegym/task/task12/task1215/Solution.java:41: error: getChild() in com.codegym.task.task12.task1215.Solution.Dog cannot override getChild() in com.codegym.task.task12.task1215.Solution.Pet public static Pet getChild(){ ^ return type com.codegym.task.task12.task1215.Solution.Pet is not compatible with java.lang.String
Vitalina Level 20, Poland
3 November 2020
You have to return an object... Eg. return new Cat();
Jonaskinny Level 25, Redondo Beach, United States
25 February 2022
or return this in each ;)
Pablo Saquilmer Level 32, Guatemala City, Guatemala
13 July 2020
This last two exercises suck they just throw this error that doesn't make sense missing method body, or declare abstract
Slawomir I. Level 15, Warsaw, Poland
27 May 2020
remember you can return null when you must create methods;
FullMet Level 29, Kyiv, Ukraine
11 April 2020
Try to use ctrl + O in Inteliji Idea to override methods
Agent Smith Level 38
24 August 2020

Ctrl + I // Implement

Ctrl + O // Override
Vj Level 1, Dallas, USA Expert
27 February 2020
Returning Objects in Abstract Class Task is really good stuff..
Manish Sinha Level 26, london, United Kingdom
8 February 2020
Good Stuff team ..thanks