JavaRush/Courses/New Java Syntax/Practicing initializing objects

Practicing initializing objects

Open

"Hi, Amigo! I already miss our lessons. Here are a few tasks to practice object initialization:"

10
Task
New Java Syntax,  10 level,  4 lecture
Locked
Populate the Friend class
Populate the Friend class
10
Task
New Java Syntax,  10 level,  4 lecture
Locked
Populate the Dog class
Populate the Dog class
10
Task
New Java Syntax,  10 level,  4 lecture
Locked
Let's put together a rectangle
Let's put together a rectangle
10
Task
New Java Syntax,  10 level,  4 lecture
Locked
Initializing objects
Initializing objects
10
Task
New Java Syntax,  10 level,  4 lecture
Locked
Initializing cats
Initializing cats
10
Task
New Java Syntax,  10 level,  4 lecture
Locked
Populate the Circle class
Populate the Circle class
10
Task
New Java Syntax,  10 level,  4 lecture
Locked
Initializing objects
Initializing objects
Комментарии (3)
  • популярные
  • новые
  • старые
Для того, чтобы оставить комментарий Вы должны sign in
Anonymous #3296229
Уровень 12
26 April 2023, 15:34
Initializing cats is a good example of how to not write your code
Alexander AfoninQA Automation Engineer at Altermail
19 May 2023, 12:10
Never-ever initialize your objects, like it was shown in Initializing Cats. Do this, if you want to have default values:
public class Cat {
String name;
int age = 2;
int weight = 3;
String color = "Black";

public void initialize (String name) {
        this.name = name;
    }
NEVER do this:
public class Cat {
String name;
int age;
int weight;
String color;

public void initialize (String name) {
        this.name = name;
        this.age = 2;
        this.weight = 3;
        this.color = "Black";
    }
There is a special place in Hell for programmes who write such code. Trust me.
Andrei Karavai
Уровень 30
4 November 2023, 00:27
🤣I'm not a programmer yet, so this Hell's not for me anyways