Christmas tree

Report a typo

You have an outer class ChristmasTree and an inner class TreeTopper. Both classes have the field color.

In the TreeTopper class create a method void sparkle.

For silver tree topper and green Christmas tree the output of sparkle should be:

Sparkling silver tree topper looks stunning with green Christmas tree!

In the outer class create a method void putTreeTopper with one string parameter color.
In this method, you should create an instance of an inner class with the parameter color, then call the method sparkle of TreeTopper.

Please, don't use private access modifier for methods.

Write a program in Java 17
class ChristmasTree {

private String color;

public ChristmasTree(String color) {
this.color = color;
}

// create method putTreeTopper()

class TreeTopper {

private String color;

public TreeTopper(String color) {
this.color = color;
}

// create method sparkle()
}
}

// this code should work
class CreateHoliday {

public static void main(String[] args) {

ChristmasTree christmasTree = new ChristmasTree("green");
christmasTree.putTreeTopper("silver");
}
}
___

Create a free account to access the full topic