"I can see that you've already rested. Great! Here are some tasks to practice creating constructors:"
10
Task
New Java Syntax,
level 10,
lesson 6
Locked
You can't buy friends
A friend (Friend class) must have three constructors:
- Name
- Name, age
- Name, age, sex.
10
Task
New Java Syntax,
level 10,
lesson 6
Locked
The basis of a wheel
In the Circle class, create a constructor that initializes all the instance variables.
The constructor must have three parameters.
10
Task
New Java Syntax,
level 10,
lesson 6
Locked
Populate the Rectangle class
The parameters for the rectangle (Rectangle class) will be top, left, width, and height.
Create as many constructors as possible.
Examples:
- 4 parameters are specified: left, top, width, height
- width/height is not specified (both are 0);
- height is not specified (it is equal to the width), we'll
10
Task
New Java Syntax,
level 10,
lesson 6
Locked
Constructor
Figure out what the program does. Find and fix one bug in the Circle class. Don't change the main method.
Hint: Study the default constructor.
10
Task
New Java Syntax,
level 10,
lesson 6
Locked
Creating cats
A cat (Cat class) must have five constructors:
- Name
- Name, weight, age
- Name, age (standard weight)
- Weight, color (name, address, and age are unknown; the cat is homeless);
- Weight, color, address (someone else's pet).
The constructor's job is to make the object valid.
For example, if the wei
10
Task
New Java Syntax,
level 10,
lesson 6
Locked
Calling a constructor from a constructor
Figure out what the program does.
Correct the constructor with two parameters so that it calls another constructor with a radius of 10. Think about which constructor you need to call.
Hint: carefully study the implementation of the default constructor.
10
Task
New Java Syntax,
level 10,
lesson 6
Locked
Max constructors
Study the Circle class. Write the maximum number of possible constructors with different arguments.
Hint: Don't forget about the default constructor.
GO TO FULL VERSION