Runtime exceptions in java

RuntimeExceptions are those exceptions which are checked at runtime. RuntimeException is the superclass of all those exceptions that can be thrown during the normal execution of the Java program. These are also called as unchecked exceptions. RuntimeException and their subclasses are known as unchecked exceptions. RuntimeExceptions can be avoided by programmer. Examples – ArithmeticException, ArrayStoreException, … Read more

Exception hierarchy in java

Exception Hierarchy: Throwable is the super class.  Hierarchy Exception Hierarchy Error Throwable Error AssertionError LinkageError BootstrapMethodError ClassCircularityError ClassFormatError UnsupportedClassVersionError ExceptionInInitializerError IncompatibleClassChangeError AbstractMethodError IllegalAccessError InstantiationError NoSuchFieldError NoSuchMethodError NoClassDefFoundError UnsatisfiedLinkError VerifyError ThreadDeath VirtualMachineError InternalError OutOfMemoryError StackOverflowError UnknownError Exception CloneNotSupportedException InterruptedException IOException FileNotFoundException SocketException ConnectException UnknownHostException ReflectiveOperationException ClassNotFoundException IllegalAccessException InstantiationException InvocationTargetException NoSuchFieldException NoSuchMethodException RuntimeException ArithmeticException ArrayStoreException ClassCastException ConcurrentModificationException … Read more

Error and exception in java

Exceptions: Exception in java, represents an exceptional event. It is an event that disrupts the program’s normal flow, during program execution. We can handle exceptions by using try-catch or throws keywords. Exceptions are divided into following two categories:  checked exceptions and unchecked exceptions. e.g. – NullPointerException, ArithmeticException, IOException, SQLException etc. Note: Exceptions generally occur because … Read more

what is an exception?

Exception refers to an exceptional event. Exception is an event that disrupts the normal flow of the program, during program execution. Java interview questions on exception handling what is an exception? How the exceptions are handled in java? What is the difference between error and exception in java? Can we keep other statements in between … Read more

can we declare local inner class as abstract?

Yes, we can declare local inner class as abstract. Example class OuterTest { public void getValue() { int num = 40;   // Abstract Local inner Class abstract class AbstractInnerTest {   abstract void getRemainder();   }   class InnerTest extends AbstractInnerTest { public int divisor; public int remainder;   public void getRemainder() { divisor … Read more

can abstract class be final in java?

No, abstract class can’t be final in Java because abstract classes are used only by extending and if they made final they can’t extended. Example final abstract class DisplayTest {   abstract void display(String str);   }   public class Main extends DisplayTest { public void display(String str) { System.out.println("Hello " + str); }   … Read more

can abstract class have constructors in java?

Yes, abstract class have constructors in java. But it is not used to instantiate abstract class. It is used in constructor chaining or to initialize abstract class common variables. Example: abstract class DisplayTest { protected final String website; abstract void display(String str);   DisplayTest(String website){ this.website = website; } }   public class Main extends … Read more

Abstract class vs interface in java

Abstract class and interface both of these are used to achieve abstraction where the abstract method can be declared. Abstract class and interface both of these cannot be instantiated. But there are many variations between abstract class and interface which are given below.   Abstract class Interface It can have method body (non-abstract methods) i.e. … Read more