أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
Yes, we can override that method which throws NullPointerException in superclass and throws Runtime Exception in subclass.Here is an example:
class First { void method() throws NullPointerException { } } class Second extends First { void method() throws RuntimeException { } }
Yes, we can override that method which throws NullPointerException in superclass and throws Runtime Exception in subclass.
Yes.
Firstly, the 'throws' is only meant to be used on checked exceptions.
Both exceptions you mention here are 'RuntimeException's (actually NullPointerException is a subclass of RuntimeException), which are unchecked exceptions. This means that they are not checked at compile time. In fact, you can have your subclass throw a runtime exception even if the super class doesn't throw any exceptions.
Yes it is possible.NullPointerException is a Runtime Exception
Yes, we can override the method in sub class.
Yes you can because NullPointerException is a child class of RuntimeException .
Both are UnChecked Exception .
Yes, we can override that method
Yes, we can override that method which throws NullPointerException in superclass and throws Runtime Exception in subclass.Here is an example:
Class first
{
void method throws NullPointerException
{}
}
Class Second extends first
{
void method() throws RunTime Expection
{}
}
One of the most important thing is, When you override any method in subclass, that method never throws any checked exception.The overriding method can throws any checked/Runtime exception.Overridden method in Java shares same name as original method in Java but can only be overridden in sub class. Original method has to be defined inside interface or base class, which can be abstract as well.When you override a method in Java its signature remains exactly same including return type. JVM resolves correct overridden method based upon object at run-time by using dynamic binding in Java.Overloaded method can be subject to compile time binding but overridden method can only be bind at run-time. Static method can not be overridden in Java.
Source:-http://tech.queryhome.com/4/nullpointerexception-override-method-runtimeexception