Вы находитесь на странице: 1из 24

SUBMITTED BY: ANJU MEHTA SONALI SHARMA

Object

oriented programming is an approach that provide a way of modularizing programs by creating partition memory area for both data & functions that can be used as a template for creating copies of such module on demand.

Emphasis is on data rather than procedure. Programs are divided into what's are known as objects. Data structures are designed such that they characterize the objects. Methods that operate on the data of an object are tied together in the data structure. Data is hidden & cannt be accessed by external functions. Objects may communicate with each other through method. New data & method can be easily added whenever necessary. Follows bottom up approach in program design.

Object Classes Data

abstraction Data encapsulation Inheritance Polymorphism

Objects

are the basic run time entities in an object oriented system. they may represent a person, a place, a bank account, a table of data or any item that the program may handle. They may also represent user defined data type such as vector & lists.

person name Basic pay Salary() Text() creation of objects

Object Data

Methods

<class name><object name>= new <class name>(); // declaration & initialization <class name><object name>; // declaration <object name>= new <class name>(); // initialization

A class

is a blueprint that defines the variables and methods common to all objects of a certain kind. A class is a collection of member data, attributes & member functions. Member data specifies the type of data to be stored. Member function act as a mediator b/w user & data.

L 4.3

<Access specifier> class <class name> { public static void main(String args[]) //member data; // member function; }

public class Box { double width; double height; double depth; } public class BoxDemo { public static void main(String args[]) { Box mybox = new Box(); double vol; mybox.width = 10; mybox.height = 20; mybox.depth = 15; vol = mybox.width * mybox.height * mybox.depth; System.out.println ("Volume is " + vol); } }
L 4.8

Access specifiers

specifies the scope of member data, member function, class & interface. 4 types of access specifiers  Public: used anywhere  Protected: within a class & derived class  Private :within a class  Default: within current package/folders

Public:

main can be access from anywhere Static: no object is required to invoke main Void: doesnt return any value Main: name of function that get execute String args[]: command line argument, data type is string array[].

Abstraction

refers to the act of representing essential features without including the background details & explainations. Summarizes the data.

The

wrapping up of data & method into a single unit is known as encapsulation. Encapsulation is the most striking featres of classs. The data is not accessible to the outside world & only those method which are wrapped in the class can access it. This insulation of data from direct access by the program is called data hiding.

Inheritance is

a process by which object of one class acquire the properties of objects of another class. Inheritence supports the concept of hierarhical classification. The class that gives the properties is called base/super/parent class. The class that receives the properties is called derived/sub/child class.

Software

Reusability (among projects) Increased Reliability (resulting from reuse and sharing of well-tested code) Code Sharing (within a project) Consistency of Interface (among related objects) Software Components Information Hiding

L 5.1

Acquiring the properties of an existing Object into newly creating Object to overcome the redeclaration of properties in deferent classes. These are 3 types: 2.Hierarchical Inheritance

1.Simple Inheritance
SUPER

SUPER extends
SUB
L 5.3

extends SUB 1 SUB 2

2. Multi Level Inheritance


SUPER 1

3. Multiple Inheritance
SUPER 2

SUPER extends SUB extends


SUB SUB

implements
SUPER 1 SUPER 2

SUB extends implements SUB

L 5.4

Interface is

a collection of method declaration. If any class implements an interface, it provides definition for all the method declared within the interface. A class can implement one or more interface. Apart from interface method class can also have its own method. Interface can contain only static final data. By default all the method declared within the interface are abstract & final.

Polymorphism

is another important oops

concept. It means the ability to take more than one form(one name multiple forms).

Java

allows abstract classes

use the modifier abstract on a class header to declare an abstract class abstract class Vehicle {}

An

abstract class is a placeholder in a class hierarchy that represents a generic concept


Vehicle

Car
L 7.8

Boat

Plane

An abstract class often contains abstract methods, though it doesnt have to




Abstract methods consist of only methods declarations, without any method body

public abstract class Vehicle { String name; public String getName() { return name; } \\ method body abstract public void move(); \\ no body! }
L 7.9

An

abstract class often contains abstract methods, though it doesnt have to


Abstract methods consist of only methods declarations, without any method body

The

non-abstract child of an abstract class must override the abstract methods of the parent An abstract class cannot be instantiated The use of abstract classes is a design decision; it helps us establish common elements in a class that is too general to instantiate

L 7.10

Inheritance allows a sub-class to override the methods of its super-class. A super-class may altogether leave the implementation details of a method and declare such a method abstract: abstract type name(parameter-list); Two kinds of methods: 1) concrete may be overridden by sub-classes 2) abstract must be overridden by sub-classes It is illegal to define abstract constructors or static methods.

L 7.11

Вам также может понравиться