"I can see that you've already rested. Great! Here are some tasks to practice creating constructors:"
5
Task
New Java Syntax,
level 5,
lesson 9
Locked
Nerd break
Did you know that before the final power lift and transition to Level 5, you need to relax a bit and watch a video from the "Did You Know?" series. This isn't just entertainment. It's part of the comprehensive curriculum developed by the pedagogical board at the secret CodeGym center. The video is dedicated to the technologies and progress achieved by mankind.
estoy confundida. que es esto?
public Color color;
no es una variable porque no tiene el tipo.
no es un constructor porque le falta (){
Alguien me puede decir que es:
gracias...
I don't think the "Constructor" task is "Medium": it is more likely "Hard" or even "Insane" :-)
Btw. if you are, like me, puzzled with two classes within the same class, this is called "nested classes" and this topic is explained later in "Java Multithreading" course (level 20+). Or you can peep at this article:
https://codegym.cc/groups/posts/262-nested-inner-classes
Best exercise was calling a constructor with another constructor. So "this" is also a method that can be called. I feel like I just begin to understand the power of this...
El ejercicio «Constructor» me pareció algodifícil de ver. Debería ser de difícultad media o mayor. Muy aparte de eso, qué gran ejercicio; me hizo pensar bastante.
Task 22: Max Constructors: What about constructing a Circle object from another Circle object? Doesn't that make 5 possible constructors?
Justin SmithLevel 41, Greenfield, USA, United States
6 July 2021
Found something that I would consider a bug in "Constructor". If you change the sole class variable from public to private (we were taught previously that they should be private and only accessed by getter and setter methods), it doesn't affect the ability of the program to run as intended, but it will fail validation for that reason alone.
Justin SmithLevel 41, Greenfield, USA, United States
6 July 2021
It may seem super-tedious to repeat the exact same tasks we did with initialize, but the point is to make some of these processes automatic for the learner.
I found the bug in this problem. But I have a basic question. Arent we to initialize the object with something like
this.color = color
public class Circle {
public Color color;
public static void main(String[] args) {
Circle circle = new Circle();
circle.color.setDescription("Red");
System.out.println(circle.color.getDescription());
}
public void Circle() {
color = new Color();
}
public class Color {
String description;
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
}
I am not clear how this initializing the object with a new works inside a constructor. Can someone please help clarify ?
I have been using a different naming convention to help differentiate the parameters. Is this considered bad form and if so is there a better way to do it.
Thanks in advance.
EXAMPLE.
GO TO FULL VERSION