- ANumberFormatException
- BArithmeticException
- CNullPointerException
- DNone of these
Correct Option: B
Correct Answer: ArithmeticException
Correct Answer: ArithmeticException
ArithmeticException
Test your knowledge of Java exceptions with these multiple choice questions. Learn about the different types of exceptions in Java and how to use them to handle errors and exceptional conditions in your programs. Take the quiz now!
class SalaryCalculationException extends Exception{} class Person{ public void calculateSalary() throws SalaryCalculationException{ //... throw new SalaryCalculationException(); //... } } class Company{ public void paySalaries(){ new Person().calculateSalary(); } }
Which of the following statements is correct?
1. This code will compile without any problems.
2. This code will compile if in method paySalaries() we return a boolean in stead of void.
3. This code will compile if we add a try-catch block in paySalaries().
4. This code will compile if we add throws SalaryCalculationException in the signature of method paySalaries().
class SuperClass{ public int doIt(String str, Integer... data)throws Exception{ String signature = "(String, Integer[])"; System.out.println(str + " " + signature); return 1; } } public class Test extends SuperClass{ public int doIt(String str, Integer... data){ String signature = "(String, Integer[])"; System.out.println("Overridden: " + str + " " +signature); return 0; } public static void main(String... args){ SuperClass sb = new Test(); sb.doIt("hello", 3); } }