In all ages, the rainbow has inspired artists and poets and served as a good omen for ordinary people. Programmers are also people capable of admiring the beauty of nature. Since we're talking about the aesthetics of the rainbow, let's create 7 objects. Each of them will display the name of one of the colors of the rainbow.
Roy G. Biv…
- 3
Locked
Comments (24)
- Popular
- New
- Old
You must be signed in to leave a comment
Kalyan Kumar Paramanandam
18 October 2020, 01:22
The order in which the objects are created must correspond to the order of the colors in the rainbow. even though the output is
Red
Orange
Yellow
Green
Blue
Indigo
Violet
0
Matthäus Schüle
12 August 2020, 19:31
I am ok with it, that i have to create the objects. What i dont get here is the fact, that i do not have to call the mehtods inside the different colour classes ... why is this so? :)
0
Daniel
28 April 2020, 17:57
/* Comment has been deleted */
0
Roman
29 April 2020, 07:27
Posting the solution in the comments is prohibited.
0
Sweetyyy Angel
3 April 2020, 06:23
i just created an object.Then,how it displays the color ????
+1
Gellert Varga
5 April 2020, 23:38
It is need to know the constructor is just a method. When it's called, it will execute every commands in it. Even this included System.out.print command, too! Which one has nothing to do with constructing the object.
You can put also any other commands into the constructor method.
But it's not the best to do this.
+3
Nickolas Johnson
17 February 2020, 19:09
I guess I should have realized class constructors always run when the object is created
+1
Michael T Schaefer
11 January 2020, 23:01
On my first try, I did...
It didn't compile and gave me this output: "Error in com/codegym/task/task03/task0315/Solution.java on line 11
cannot find symbol
symbol: method Red()
location: class com.codegym.task.task03.task0315.Solution"
What confuses me is that it seemed that what we were asked to do was the same as in the Level 2, Lesson 3 task ("One cat isn't enough). Clearly it's not though. It obviously has something to do with that "public Red... System.out.print..." code. Can anyone explain why?
0
Roman
13 January 2020, 14:49
Please refer to Help section at our course.
+1
Vaibhavi
28 November 2019, 12:25
Please clarifz the code , I did this way but still facing Issues on the same
0
Muhammad Vahhaaj
4 June 2019, 19:21
Just:
new Red();
new Orange();
creates new objects and if you are guessing the automatic output it's because of default constructors(println in constructors)
+4
pravin
30 May 2019, 05:49
public class Solution {
public static void main(String[] args) {
//write your code here
Red red = new Red();
}
public static class Red {
public Red() {
System.out.println("Red");
}
}
}
output of these program is red
i want ask you that how object call the method.
0
Luyi
6 May 2019, 09:10
maybe it help for someone:
https://stackoverflow.com/questions/7486012/static-classes-in-java // I have found it useful
+1