OOPS-BASICS

 OOPS is a method of implementation in which programs are organized as collections of objects, class and methods.

Major concept of oops:

  1. Class
  2. Objects
  3. Methods
  4. Abstraction
  5. Encapsulation
  6. Inheritance
  7. Polymorphism

1.Class

  • Class is nothing but collections of methods and Objects.
  • Class is a Blueprint for creating Objects by providing number variables and member functions.
  • Class = Attribute + Behavior
    • Attribute – Properties [ Example: CAR: Color, Model, Year ]
    • Behavior – Methods [ Example: Brake, Accelerate, Turn]
  • A class is an abstract datatype which consists of set of objects that share common structure and common behavior.

2.Objects:

  • An Object comes from a class. A unique occurrence from a class is called as instance.
  • An Object is an instance of a class ,creating an object is also known as instantiation.

3.Methods

A method is behavior of an object, within the program, a method usually affects only one particular object.

  • Example: get()
  • on()
  • turn()
  • accelerate()
  • brake()

4.Abstract

  • Hiding the implementation part is called abstraction, we do not create object for abstraction.
  • Abstraction is a process is to show only “relevant data” and ” hide unnecessary details of an object from the user is called as Data Abstraction.

Example :ATM Machine Operations on the ATM machine like cash withdrawal, money transfer, retrieve mini-statement…etc. but we can’t know internal details about ATM.

5.Encapsulation

The “Wrapping Up” of data and the functions into a single unit is called Encapsulation. This features keeps the data safe from outside interference

Example: Medical capsule. This capsule mixes few types of medicines and stored in one capsule.

6.Inheritance

  • Inheritance is a mechanism of deriving new class from an old class that is pre-defined.
  • We can access one class property into another class using ‘extend’ keyword.
  • Inheritance concept is mainly used for code reusability.

old class -> Base (or) Super (or) Parent class

New class -> sub (or) derived (or) child class

Example: Parent class as Animals. Here also we can inherit common properties like name, sound, color, breed from Animal class and create classes like Dog, Cat, Horse and etc.

Types of Inheritance:

  1. Single Inheritance
  2. Multilevel Inheritance
  3. Multiple Inheritance
  4. Hybrid Inheritance
  5. Hierarchical Inheritance

Single InheritanceOne parent class is directly support into one child class .

Multilevel Inheritance: One child class and more than one parent class.

Multiple Inheritance: More than one parent class parallelly support into one child but it will not support in java because

  1. priority problem
  2. Compilation error/syntax error

Hybrid Inheritance: It is a combination of single and multiple inheritance

Hierarchical Inheritance: One parent class and more than one child class.

7. Polymorphism:

poly -> many ; morph -> shape

  • The ability to take more than one form is called polymorphism.
  • An operation may exhibit different behavior in different instance. The behavior depends upon the types of data in the operation.

Example:  Sound of animals. People have the same sound but different animals make different sounds.

Comments

Popular posts from this blog

"Don't Believe Everything You Think"-Joseph Nguyen

HOW JAVA WORKS

How Java Works (Interview Question Answers)