oops in java

22

Upload: baabtracom-no-1-supplier-of-quality-freshers

Post on 15-Jul-2015

303 views

Category:

Education


1 download

TRANSCRIPT

Date:06/01/2015

[email protected]

facebook.com/Manu-Kannan

twitter.com/baabtra

in.linkedin.com/in/baabtra

OOPs concepts in Java

What is OOP?

● Object-oriented programming (OOP)style of

programming that focuses on using objects to

design and build applications.

● Think of an object as a model of the concepts,

processes, or thing in the real world that are

meaningful to your application.

What Are Objects?

● Software objects model reaL-world objects- dog, bicycle, etc.

● Real-world objects have states and behaviors-Bicycle’s states or properties: name, color, model-Bicycle’s behaviors or action : riding, changing gears

● How do Software objects implement real-world objects?-Use variables to implement states-Use methods to implement behaviors

● An object is a software bundle of variables and related methods

Definition

● Class : -is the base design of objects

● Object :- is the instance of a class

• No memory is allocated when a class is created.

• Memory is allocated only when an object is created.

OOP FEATURES

● Abstraction

● Encapsulation

● Polymorphism

● Overriding

● Inheritance

● Interfaces

Data Abstraction

● Abstraction refers to the act of

representing essential features without

including the background details or

explanations.

● Since the classes use the concept of data

abstraction , they are known as the

abstract data types.

Encapsulation

● The wrapping up of data and functions into a

single unit is known as Encapsulation.

● The data is not accessible to the outside world

and only those functions which are wrapped in

the class can access it.

● This insulation of the data from direct access

by the program is called Data hiding or

information hiding.

Polymorphism

In polymorphism refers to a programming language

ability to process objects differently depending on

their data type or class.

More specifically, it is the ability to redefine

methods for derived classes.

For example,

given a base class shape , polymorphism enables

the programmer to define different area methods

for any number of derived classes, such as circles,

rectangles and triangles. No matter what shape an

object is, applying the area method to it will return

the correct results. Polymorphism is considered to

be a requirement of any true object-oriented

programming language (OOPL).

ExamplePublic class shape

{

int calculateArea(int width,int height)

{

return width*height;

}

float calculateArea(int radius)

{

return(22/7)*radius*radius;

}

}

public class example

{

Public static void main(string args[])

{

Shape sh=new shape();

System.out.println(sh.calculateArea(10));

}

}

Method Overriding

● We have two classes and both classes have a function

with the same name and same Parameters inheritance is

necessary.

● For Example

class B

{

public void f1(int x,int y)

{

System.out.println(x+y);

}

}

class A extends B

{

public void f1(int x,int y)

{

System.out.println(x*y);

}

public static void main(String ar[])

{

A a=new A();

a.f1(5,5);

B b=new B();

b.f1(2,3);

}

}

Inheritance● In object-oriented programming, inheritance is the

concept that when a class of objects is define, any

subclass that is defined can inherit the definitions of one

or more general classes.

● This means for the programmer that an object in a

subclass need not carry its own definition of data and

methods that are generic to the class (or classes) of

which it is a part.

● This not only speeds up program development; it also

ensures an inherent validity to the defined subclass

object .

ExamplePublic class shape

{

protected int width;

protected int height;

Int calculateArea(int x,int y)

{

Return x*y;

}

Public class dimensionshape extends shape

{

Private int depth;

Int calculateVolume()

{

Return width*height*depth;

}

Interface● An interface is a collection of abstract methods (it means

all methods are only declared in an Interface). ● A class implements an interface, thereby inheriting the

abstract methods of the interface.● And that class implements interface then you need to

defined all abstract function which is present in an Interface.

● An interface is not a class. ● Writing an interface is similar to writing a class, but they

are two different concepts. ● A class describes the attributes and behaviors of an object

and interface contains behaviors that a class implements.

Exampleinterface Idemo

{

public void findSquare(int x);

}

class Demo implements Idemo

{

public void findSquare (int x)

{

System.out.println ("Square is "+(x*x));

}

public static void main (String ar[])

{

Demo dm=new Demo ();

dm.findSquare (10);

}

}

➸THANK YOU☺

US UK UAE

7002 Hana Road,

Edison NJ 08817,

United States of America.

90 High Street,

Cherry Hinton,

Cambridge, CB1 9HZ,

United Kingdom.

Suite No: 51, Oasis Center,

Sheikh Zayed Road, Dubai,

UAE

Email to [email protected] or Visit baabtra.com

Looking for learning more about the above

topic?

India Centres

Emarald Mall (Big Bazar Building)

Mavoor Road, Kozhikode,

Kerala, India.

Ph: + 91 – 495 40 25 550

NC Complex, Near Bus Stand

Mukkam, Kozhikode,

Kerala, India.

Ph: + 91 – 495 40 25 550

Cafit Square IT Park,

Hilite Business Park,

Kozhikode

Kerala, India.

Email: [email protected]

TBI - NITC

NIT Campus, Kozhikode.

Kerala, India.

Start up Village

Eranakulam,

Kerala, India.

Start up Village

UL CC

Kozhikode, Kerala

Follow us @ twitter.com/baabtra

Like us @ facebook.com/baabtra

Subscribe to us @ youtube.com/baabtra

Become a follower @ slideshare.net/BaabtraMentoringPartner

Connect to us @ in.linkedin.com/in/baabtra

Give a feedback @ massbaab.com/baabtra

Thanks in advance

www.baabtra.com | www.massbaab.com |www.baabte.com

Want to learn more about programming or Looking to become a good programmer?

Are you wasting time on searching so many contents online?

Do you want to learn things quickly?

Tired of spending huge amount of money to become a Software professional?

Do an online course @ baabtra.com

We put industry standards to practice. Our structured, activity based courses are so designedto make a quick, good software professional out of anybody who holds a passion for coding.