Sunday, 27 December 2015

Basic Oops concept

Basic Oops concept are : 
  1. Inheritance
  2. Polymorphism
  3. Encapsulation
  4. Abstraction
1. Inheritance : 
Inheritance is one such concept where the properties of one class can be inherited by the other. It helps to reuse the code and establish a relationship between different classes.

In Java, there are two classes:
  • Parent class ( Super or Base class)
  • Child class (Subclass or Derived class )
A class which inherits the properties is known as Child Class whereas a class whose properties are inherited is known as Parent class.

Read more about Inheritance here.

2. Polymorphism :
Polymorphism means taking many forms, where ‘poly’ means many and ‘morph’ means forms. It is the ability of a variable, function or object to take on multiple forms. Polymorphism in Java is of two types:
  1. Run time polymorphism 
  2. Compile time polymorphism
Read more about Polymorphism here


3. Encapsulation :
Encapsulation is a mechanism where you bind your data and code together as a single unit. It also means to hide your data in order to make it safe from any modification. 

We can achieve encapsulation in Java by:
Declaring the variables of a class as private. Providing public setter and getter methods to modify and view the variables values.

Read more about Encapsulation here.

4. Abstraction :

Abstraction is process of hiding the implementation details and showing only the functionality. 

Abstraction in java is achieved by using interface and abstract class. Interface give 100% abstraction and abstract class give 0-100% abstraction.


Read more about Abstraction here.

No of Occurrence in Array

package com.tutorial4u; import java.util.HashMap; /************************************************************  No of Occurrence in Array...