Created
          July 28, 2017 08:28 
        
      - 
      
 - 
        
Save simonovich/c35224f77191835f7fe7eb48045d74fb to your computer and use it in GitHub Desktop.  
    Создать 7 объектов, чтобы на экран вывелись 7 цветов радуги (https://javarush.ru/tasks/com.javarush.task.task03.task0315#discussion)
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package com.javarush.task.task03.task0315; | |
| /* | |
| Каждый охотник желает знать… | |
| */ | |
| import java.lang.reflect.Constructor; | |
| public class Solution { | |
| public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException { | |
| String Colors[] = {"Red","Orange","Yellow","Green","Blue","Indigo","Violet"}; | |
| for (String clr: Colors) { | |
| // Здесь полное имя класса, получить автоматически через this нельзя, т.к. main() - статический | |
| Class c = Class.forName("com.javarush.task.task03.task0315.Solution$" + clr); | |
| Constructor ctr = c.getConstructor(); | |
| Object color = c.newInstance(); | |
| } | |
| public static class Red { | |
| public Red() { | |
| System.out.println("Red"); | |
| } | |
| } | |
| public static class Orange { | |
| public Orange() { | |
| System.out.println("Orange"); | |
| } | |
| } | |
| public static class Yellow { | |
| public Yellow() { | |
| System.out.println("Yellow"); | |
| } | |
| } | |
| public static class Green { | |
| public Green() { | |
| System.out.println("Green"); | |
| } | |
| } | |
| public static class Blue { | |
| public Blue() { | |
| System.out.println("Blue"); | |
| } | |
| } | |
| public static class Indigo { | |
| public Indigo() { | |
| System.out.println("Indigo"); | |
| } | |
| } | |
| public static class Violet { | |
| public Violet() { | |
| System.out.println("Violet"); | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment