ProgrammingVery hardGATE CS · TCS NQT Prime · Product Company SDE
java Function<Integer,Integer> sq = x -> x x; Function<Integer,Integer> addOne = x -> x + 1; Function<Integer,Integer> combo = sq.andThen(addOne)…
Function<Integer,Integer> sq = x -> x * x; Function<Integer,Integer> addOne = x -> x + 1; Function<Integer,Integer> combo = sq.andThen(addOne); System.out.print(combo.apply(3));What is printed?
- A. 9
- B. 10
- C. 16
- D. 4
Correct answer: B. 10
andThen applies the original function (sq) first, then feeds its result into the argument function (addOne): 3*3 = 9, then 9+1 = 10.
More OOP with C++ and Java questions
- What does the 'Rule of Five' in modern C++ say?
- java Function<Integer,Integer> sq = x -> x x; Function<Integer,Integer> addOne = x -> x + 1; Function<Integer,Integer> combo =…
- java class Base { int v = 1; } class Derived extends Base { int v = 2; } // main: Base b = new Derived(); System.out.print(b.v); What is…
- In C++, a base class constructor calls a function that is overridden in a derived class. Which version actually runs while the base…
- A PaymentMethod type requires every concrete implementation to provide charge() and refund(), but there is no shared implementation at all…
- Which kind of call in C++ is resolved using static (compile-time) binding rather than dynamic (run-time) binding?