Multiple choice technology programming languages

Select three correct statements about the following code :-- public class TechnoSample { public static void main(String[] args) { TechnoSample myref = new TechnoSampleSub(); try{ myref.test(); } catch(Exception e){} } void test() throws Exception{ System.out.println("In TechnoSample"); throw new Exception(); } } class TechnoSample Sub extends TechnoSample { void test() { System.out.println("In TechnoSampleSub"); } }

  1. The try-catch block that encloses myref.test(); is mandatory for the code to compile

  2. Prints: In TechnoSample

  3. Prints: In TechnoSampleSub

  4. Method test() in class TechnoSampleSub has no obligation to declare a throws clause

  5. An exception is thrown at runtime

Reveal answer Fill a bubble to check yourself
A,C,D Correct answer
Explanation

The try-catch is mandatory because the reference type TechnoSample has a test() method declaring throws Exception, so callers must handle it. The output is 'In TechnoSampleSub' because Java invokes the subclass method at runtime due to polymorphism. The subclass method can choose not to throw exceptions since overriding methods may declare fewer exceptions than the superclass version.