Question: / / Step 2 : Create a new Java class named Color public class Color { / / Step 3 : Declare one data member
Step : Create a new Java class named Color public class Color Step : Declare one data member of type String named "color" private String color; Step : Define a method named setColor with one parameter String colorName and void return type public void setColorString colorName this.color colorName; Assign colorName to color data member Step : Define a method named getColor with no parameters and String return type public String getColor return this.color; Return color when the method is called Step : Inside the main method, create an object of class Color public static void mainString args Color myColor new Color; Create an object of class Color Step : Using the object, call setColor and pass any color you like to it myColor.setColorBlue; Step : Call getColor and print its value System.out.printlnThe color is: myColor.getColor;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
