0
What is the Output of this Code?
Please tell me the Output of the following Code: public class Challenge { private String task; private String company = "BSI"; private Stream<String> hiring = Stream .of("sucht", "Software Engineers", "zur", "Verstärkung"); public Challenge(String scope) { task = "CODE-RÄTSEL KNACKEN"; } protected Challenge() { company = "RECRUITING-MESSE BESUCHEN"; } protected String getHiring() { return hiring.filter(s -> s.length() == 0b101).findFirst() .orElse("RASPBERRY PI TOUCH"); } @Override public String toString() { return task = company; } public static void main(String args[]) { Challenge challenge = new Challenge("GEWINNEN"); System.out.print(challenge + " " + challenge.getHiring()); } } Thanks in advance!
1 Odpowiedź
+ 1
It will be "BSI sucht".
Explanation:
main function creates a new Challenge => the Challenge constructor with string parameter sets task to "CODE-RÄTSEL KNACKEN"
Then it prints challenge.toString() (implicitly) and challenge.getHiring()
The toString sets the company's value to task and returns it, so it will return "BSI" (the current company's value)
The getHiring finds the first value in the hiring string that has 5 letters (binary 101 is 5 decimal), it's "sucht" (if there isn't any it will return "RASPBERRY PI TOUCH"
Then, the string printed will be:
BSI sucht
Edit: excuse me, I didn't see the toString function, now the result and explanation are ok