Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Animal Information Display | Classes Advanced
Java Extended
course content

Kursinnhold

Java Extended

Java Extended

1. Deep Java Structure
2. Methods
3. String Advanced
4. Classes
5. Classes Advanced

book
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.

  1. Create two objects of the Animal class — one for a cat and one for a dog.
    • You need to create an object cat of the Animal class with the type "Cat", name "Garfield", and color "Red".
    • You also need to create an object dog of the Animal class with the type "Dog", name "Maks", and color "Black".
  2. Create and use the Animal(String type, String name, String color) constructor to pass the parameters type, name, and color for each object.
  3. After creating the objects, use System.out.println() to print information about each animal.

Løsning

java

solution

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 5. Kapittel 4
toggle bottom row

book
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.

  1. Create two objects of the Animal class — one for a cat and one for a dog.
    • You need to create an object cat of the Animal class with the type "Cat", name "Garfield", and color "Red".
    • You also need to create an object dog of the Animal class with the type "Dog", name "Maks", and color "Black".
  2. Create and use the Animal(String type, String name, String color) constructor to pass the parameters type, name, and color for each object.
  3. After creating the objects, use System.out.println() to print information about each animal.

Løsning

java

solution

Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 5. Kapittel 4
Switch to desktopBytt til skrivebordet for virkelighetspraksisFortsett der du er med et av alternativene nedenfor
Vi beklager at noe gikk galt. Hva skjedde?
some-alt