Try, Catch and Finally in Exception Handling

java-thumbnail

The basic procedure to handle the exception is to use the try-catch block. If you want to put any code that would cause a exception, then write that piece of code inside the try-catch block. If you expect multiple type of exceptions in the same block, then you can write more than one catch block […]

Exception Handling in Java

java-thumbnail

Exception handling is one of the important task for every programmer. For a successful project completion, proper exception handling is important. Exception is an abnormal error encountered by program which is not anticipated by the program, but it is the responsibility of a developer to gracefully handle the exceptions and redirect with suitable error message […]

Constructor in Java

java-thumbnail

Constructors are special type of methods that are invoked at the time of creating the objects. If you use new keyword for creating the object, the constructors are called. There are certain restrictions imposed on these special type of methods. Constructors should have the same name as class name Constructors should not have any return […]

Method Overloading Vs Overriding in Java

java-thumbnail

In our previous tutorials we have explained about the method overloading and method overriding in Java. Read those tutorials for the more explanations. This tutorial highlights the only differences and when we have to use both the concepts. Both the concepts are based on the polymorphism in Java. Look at the below table for the […]

Method Overloading in Java

java-thumbnail

Method Overloading is the concept of writing multiple methods with the same name. Here the common characteristic is only the name. Parameters must be different. Return type can be anything. Also note that method overloading is within same class or inherited class. Look at the below points on how to overload a method. All the […]

Method Overriding in Java

java-thumbnail

Method Overriding is concept of overriding a same method in the child class. This is fall under the dynamic polymorphism  or run time polymorphism. A method defined in the parent class is considered as the common behaviour and the child classes are expected to override the common behaviour with own implementation. There are multiple restrictions enforced […]

Instanceof Operator

java-thumbnail

Instanceof Operator is important for writing the condition to check if a particular variable reference is of specific type / class. In short it is type checking condition. This operator returns true or false depends on the condition output. It always return false if you compare null value with any class. Lets look at an […]

Instance Initializer in Java

java-thumbnail

Instance initializer in Java is used for initializing the instance variables inside a class. It is a simple block without any modifiers used inside any class. If you declare a instance variable with value, then this value can be overridden in the instance initializer or in the constructor. The order of the execution as follows: […]

Access Modifiers in Java

java-thumbnail

This tutorials explains the various access modifiers used in Java language and the scope for the each modifier. There is four types of access modifiers in Java. private default protected public Private Modifier If you declare anything private inside a class, then it must be accessed inside that class. Other classes can not access that […]

OCPJP 6 Mock Exam -10

ocpjp-6-thumbnail

1 . Given: What is the result? Compilation succeeds Compilation fails because of an error on line 1 Compilation fails because of an error on line 3 Compilation fails because of an error on line 7 2 . Given: The ClassA class can be compiled successfully by inserting one of three possible options on line 3. […]