Question: / / Step 2 : Create a new Java class named Color public class Color { / / Step 3 : Declare one data member

// Step 2: Create a new Java class named Color public class Color {// Step 3: Declare one data member of type String named "color" private String color; // Step 4: Define a method named setColor with one parameter (String colorName) and void return type public void setColor(String colorName){ this.color = colorName; // Assign colorName to color data member }// Step 5: 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 6: Inside the main method, create an object of class Color public static void main(String[] args){ Color myColor = new Color(); // Create an object of class Color // Step 7: Using the object, call setColor and pass any color you like to it myColor.setColor("Blue"); // Step 8: Call getColor and print its value System.out.println("The color is: "+ myColor.getColor()); }}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!