JavaRush /Courses /New Java Syntax /Practicing initializing objects

Practicing initializing objects

New Java Syntax
Level 10, Lesson 4
Available

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

10
Task
New Java Syntax, level 10, lesson 4
Locked
Populate the Friend class
Populate the Friend class
10
Task
New Java Syntax, level 10, lesson 4
Locked
Populate the Dog class
Populate the Dog class
10
Task
New Java Syntax, level 10, lesson 4
Locked
Let's put together a rectangle
Let's put together a rectangle
10
Task
New Java Syntax, level 10, lesson 4
Locked
Initializing objects
Initializing objects
10
Task
New Java Syntax, level 10, lesson 4
Locked
Initializing cats
Initializing cats
10
Task
New Java Syntax, level 10, lesson 4
Locked
Populate the Circle class
Populate the Circle class
10
Task
New Java Syntax, level 10, lesson 4
Locked
Initializing objects
Initializing objects
Comments (3)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
26 April 2023
Initializing cats is a good example of how to not write your code
19 May 2023
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 Level 30
4 November 2023
🤣I'm not a programmer yet, so this Hell's not for me anyways