Posts

Showing posts with the label OOPs concepts

Method Overloading Vs Method overridding

  In this blog post, I will be explaining the difference between method overloading and method overidding. What is method overloading? In Java it is possible to define two or more methods within the same class that share the same name, as long as their parameter declarations are different. When this is the case, the methods are said to be overloaded, and the process is referred to as method overloading. The following code demonstrates this: public class AddDemo {public int add(int a,int b){return a+b;}public double add(double a,double b){return a+b;}} So here this class has two methods with the name “ add “. The first version accepts two integer values and returns an int, whereas the second version accepts two double values and returns a double. So both these methods have the same name i.e. add , but accept different types of parameters. Overloaded methods must differ in the type and/or number of their parameters. While overloaded methods may have different return types...

Object oriented principles in Java Explained in Short

As you probably know, Java is an Object-oriented language. There are some fundamental object-oriented principles that are supported by Java. In this post, I will give you an overview of the object-oriented principles supported by Java. I will also explain how Java supports them. An understanding of these OOPs principles will give you a strong foundation while writing code. Abstraction Abstraction simply means hiding the internal details from the outside world. In Java, classes & methods are used to achieve abstraction. So a class hides its internal working from the outside world & only provides public methods for the functionality which the outside world needs to access. Encapsulation Wrapping together data & code that operates on the data together as a single unit is referred to as encapsulation. Again, a well-implemented java class can be an example of encapsulation. By well implemented, I mean that the correct access specifiers are used i.e. fields should have private ac...