0 day streak
Anonymous · shared experience20 Apr 2025 · 5 views

Capgemini: Predict the output: four tricky Java snippets

Interview question #Capgemini SDE 2 Other

Format. Screen shared, answers typed in a plain text editor, no IDE.

Snippets.

  • Two try-catch blocks with Integer comparisons that throw only in some cases: which blocks print?
  • A static int changed once through the class and once through an instance: what do both reads show? (Both show the same value, since the field is shared.)
  • Parent and child both declare a static test() and it is called through a parent-type reference holding a child: which runs? (The parent's, because static methods are hidden, not overridden, and bind to the reference type.)
  • An interface marked @FunctionalInterface that has only default methods: does it compile? (No; a functional interface needs exactly one abstract method.)

Also asked. In one statement, square the numbers 1 to 6, keep those above 20 and count them (answer 2).

Context. A 30 minute single round for a Java backend role at around four years of experience.

0 comments

Comments 0

No comments yet. Ask the author something, or add what happened in your own round.