I also tried removing the "\n" from the SecondClass's SPECIFIC_ACTION_FOR_ANONYMOUS_SECOND_CLASS_PARAM.
When I did that, it passed the first condition but still failed the other two
Edit:
I overrode the anonymous FirstClass's someAction() method and called the parent class method
This solved the 3rd condition
I created an anonymous SecondClass and overrode the someAction() method to print() instead of println()
This solved conditions 1 and 2
package com.codegym.task.task24.task2405;
/*
Black box
*/
public class Solution implements Action {
public static int actionObjectCount;
private int param;
private Action solutionAction = new Action() {
//write your code here
public void someAction() {
//write your code here
int temp = param;
while (param > 0){
System.out.println(param);
param--;
}
if (temp>0) {
FirstClass firstClass = new FirstClass() {
@Override
public Action getDependentAction() {
return null;
}
};
firstClass.someAction();
}
SecondClass secondClass = new SecondClass();
secondClass.someAction();
System.out.println(SecondClass.SPECIFIC_ACTION_FOR_ANONYMOUS_SECOND_CLASS_PARAM + param);
}
};
public Solution(int param) {
this.param = param;
}
@Override
public void someAction() {
solutionAction.someAction();
}
/**
* 5
* 4
* 3
* 2
* 1
* FirstClass class, someAction method
* SecondClass class, someAction method
* Specific action for anonymous SecondClass, param = 0
* The number of created Action objects is 2
* SecondClass class, someAction method
* Specific action for anonymous SecondClass, param = -1
* The number of created Action objects is 3
*/
public static void main(String[] args) {
Solution solution = new Solution(5);
solution.someAction();
System.out.println("The number of created Action objects is " + actionObjectCount);
solution = new Solution(-1);
solution.someAction();
System.out.println("The number of created Action objects is " + actionObjectCount);
}
}