Kursinnhold
Java Extended
Java Extended
Challenge: Animal Information Display
Oppgave
Swipe to start coding
Your task is to bypass the private
access modifier and create two objects with the necessary parameters, then display them.
- Create two objects of the
Animal
class — one for a cat and one for a dog.- You need to create an object
cat
of theAnimal
class with the type "Cat", name "Garfield", and color "Red". - You also need to create an object
dog
of theAnimal
class with the type "Dog", name "Maks", and color "Black".
- You need to create an object
- Create and use the
Animal(String type, String name, String color)
constructor to pass the parameterstype
,name
, andcolor
for each object. - After creating the objects, use
System.out.println()
to print information about each animal.
Løsning
solution
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 5. Kapittel 4
Challenge: Animal Information Display
Oppgave
Swipe to start coding
Your task is to bypass the private
access modifier and create two objects with the necessary parameters, then display them.
- Create two objects of the
Animal
class — one for a cat and one for a dog.- You need to create an object
cat
of theAnimal
class with the type "Cat", name "Garfield", and color "Red". - You also need to create an object
dog
of theAnimal
class with the type "Dog", name "Maks", and color "Black".
- You need to create an object
- Create and use the
Animal(String type, String name, String color)
constructor to pass the parameterstype
,name
, andcolor
for each object. - After creating the objects, use
System.out.println()
to print information about each animal.
Løsning
solution
Alt var klart?
Takk for tilbakemeldingene dine!
Seksjon 5. Kapittel 4