Category Archives: Java OOP

Diamond Problem in Inheritance

Diamond problem occurs when we use multiple inheritance in programming languages like C++ or Java. Let’s understand this with one example. Diamond Problem in Inheritance

Suppose there are four classes A, B, C and D. Class B and C inherit class A. Now class B and C contains one copy of all the functions… Read More »

Difference between Abstract Class and Interface in Java

Abstract class and interface both are used to achieve abstraction in java. Still there are lot of differences between abstract class and interface which I am sharing in this tutorial. Difference between Abstract Class and Interface in Java Difference between Abstract Class and Interface in Java – Image Source Abstract Class Interface Abstract class can… Read More »

Interface in Java

Before learning interface in java, you must know about abstraction. So lets learn about what is abstraction. Abstraction in Java Abstraction is the process of hiding the complexity and showing the functionality. Showing the essential data and hiding the non essential data.  We can understand this by taking a real world example. We have fan… Read More »

Abstract Class in Java

Before reading this tutorial I will recommend you to read about dynamic binding in java, because without knowing about dynamic binding you can’t understand the concept of abstract class in java.   Abstraction in Java Abstraction is the process of hiding the complexity and showing the functionality. Showing the essential data and hiding the non… Read More »

Static Binding and Dynamic Binding in Java

Binding is the process of connecting the method call to the method body or determining the type of the object. In Java there are two types of binding, static binding and dynamic binding. I have explained them one by one in this tutorial. Static Binding in Java 1. When type of the object is determined… Read More »

Super Keyword in Java

Super refer to parent class. It holds the reference id of parent section of child class object. Observe below example. class A {                 int x=10; } class B extends A {                 int x=20; } Here you can see that in child object, two separate sections are created namely parent section and child section.… Read More »

Inheritance in Java

Creating a new class from existing class is known as inheritance. Inheritance is used to achieve dynamic binding and reusability. The class which is inherited is known as super class or parent class and the class derived from the parent class is known as sub class or child class. Inheritance is implemented using extends keyword.… Read More »

Autoboxing and Unboxing in Java

Autoboxing and Unboxing in Java Before understanding autoboxing and unboxing in java we must know what is wrapper class. So lets take a look on it. Wrapper Class A wrapper class wraps around a primitive data type and gives it an object appearance. This wrapper class object can be used whenever the primitive data type is… Read More »

Constructor in Java

Constructor is a special method which is used to initialize the state of an object. Constructor is special method because it has following properties: – Automatically called – Constructor name is same as class name – No return type Programmer can’t call constructor explicitly. It is called automatically at the time of creation of object.… Read More »

Polymorphism in Java

Polymorphism is used to assume the ability of several different forms. Or we can say performing one task in different ways. In java + operator is used for addition as well to concatenate (join) strings. Here a single operator is doing two different things depending upon the type of argument, so it is the situation… Read More »

this Keyword in Java

this holds the reference of current object. Observe below example: class demo {                 int  x=10;                 void show(int x,demo d1)                 {                                 System.out.println(this.x);                                 System.out.println(d1.x);                                 System.out.println(x);                 }                 public static void main(String…s)                 {                                 demo d1=new demo();                       ,d1);                 } } Output: 10 10 20 In Java by default… Read More »

Classes and Objects in Java

Class Class is the collection of similar type of objects which have some common properties. Class is a concept which is implemented by object. Class is a blueprint of java program from which we create object, then object is instance of class. We can also say that class is a collection of variables and methods.… Read More »