Accenture Primer
Accenture DumpmediumAccenture PrimerAccenture-Primer-Dump

Accenture Accenture Primer Practice Question

Predict the output import java.util.Scanner; class WeightLimitExceeded extends Exception { WeightLimitExceeded(int x) { System.out.print(Math.abs(15-x) + "kg: "); } } public class Main{ void validWeight(int weight) throws WeightLimitExceeded { if(weight > 15) throw new WeightLimitExceeded(weight); else System.out.println("You are ready to fly!"); } public static void main(String[] args) { Main ob = new Main(); Scanner in=new Scanner(System.in); for(int i=0;i<2;i++) { try { ob.validWeight(in.nextInt()); } catch(WeightLimitExceeded e) { System.out.println(e); } } } } What will be the output for the given code snippet

Answer options

A
5kg : WeightLimitExceeded You are ready to fly!
B
NumberFormatException
C
5kg : You are ready to fly!
D
Cannot find symbol Math.abs

Correct answer: 5kg : WeightLimitExceeded You are ready to fly!

Explanation

For input weight=20: WeightLimitExceeded constructor prints Math.abs(15-20)=5, so '5kg: '. Then catch prints the exception object (class name) = 'WeightLimitExceeded'. For input weight=10: 'You are ready to fly!' is printed.

Related Accenture Accenture Primer questions

Practice more Accenture Accenture Primer questions

PrimerDumps has 1400+ primer questions, 2026 mocks and coding hands-on — all free.