Program to show - overridden method of subclass can declare/throw any unchecked /RuntimeException (superclass or subclass)

RuntimeException is superclass of NullPointerException.
class SuperClass{
   void method() throws NullPointerException{
          System.out.println("superClass method");

class SubClass extends SuperClass{
   void method() throws RuntimeException{
          System.out.println("SubClass method");
/** Copyright (c), AnkitMittal
* Main class */
public class ExceptionTest {
   public static void main(String[] args) {
          SuperClass obj=new SubClass();
SubClass method

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...
//start paginationJs //end paginationJs