Roy G. Biv…

  • 3
  • Locked
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.
You can't complete this task, because you're not signed in.
  • Popular
  • New
  • Old
You must be signed in to leave a comment
28 April, 17:57
/* Comment has been deleted */
RomanLevel 41
29 April, 07:27
Posting the solution in the comments is prohibited.
Sweetyyy AngelLevel 3 , Erode
3 April, 06:23
i just created an object.Then,how it displays the color ????
Gellert VargaLevel 11 , Szekesfehervar
5 April, 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.
Nickolas JohnsonLevel 8 , St. Louis
17 February, 19:09
I guess I should have realized class constructors always run when the object is created
Michael T SchaeferLevel 9 , Belleville
11 January, 23:01
On my first try, I did... It didn't compile and gave me this output: "Error in com/codegym/task/task03/task0315/ 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?
RomanLevel 41
13 January, 14:49
Please refer to Help section at our course.
Vaibhavi Level 5 , Vijayawada
28 November 2019, 12:25
Please clarifz the code , I did this way but still facing Issues on the same
Muhammad VahhaajLevel 19 , Rawalpindi
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)
pravinLevel 4 , Nagpur
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.
LuyiLevel 31 , Kosice
6 May 2019, 09:10
maybe it help for someone: // I have found it useful
DerekLevel 11 , Apex, NC
18 March 2019, 19:08
my initial thought was along the lines of Red red = new Red(); red.Red(); but this didn't work. Syed's example below works, but I don't know why. Seems the Red() method within the class is being called automatically without being explicitly called. Any explanation why?
Jesús de LleraLevel 23 , Badajoz
25 March 2019, 20:20
You are actually calling the method inside the class (it's called constructor method) when you type 'new' + 'name of the class'. For instance, new Red() calls the constructor method 'public Red()'.
Syed Tayyab ul MazharLevel 12 , Karachi
1 January 2019, 17:47
Red red = new Red(); Orange orange = new Orange();