Skip to content
CodeKruPro

return in try and finally

QuizMediumJava onlyAsked in: Accenture, Capgemini, Cognizant, Infosys, TCS

What do t() and u() return?

static int t() {
    try { return 1; } finally { return 2; }
}
static int u() {
    int x = 1;
    try { return x; } finally { x = 5; }
}
  • t() returns 2 and u() returns 1
  • t() returns 1 and u() returns 1
  • t() returns 2 and u() returns 5
  • Neither compiles

This question is part of Pro+

Pro+ opens every question in Interview Prep and the mock interview. Every article and the first 2 questions of each topic stay free. Hands-on Selenium and API tasks follow their course lesson's own lock.

See Pro+

Already have Pro+? Sign in