Vous êtes sur la page 1sur 4

Java

System.out.println ();
Scanner scan1=new scanner (system.in);
System.out.println (enter a number);
Int x=scan1.nextint ();
METHODS
Public static void method()
{
}
Publicaccess modifiers
Static --- belong to class
Void --- return type
Access modifiers
Access levels
modifiers
class

Package

subclass

world

Public

protected

No modifiers

private

For private variable use getter and setter functions


Static keyword: Static member belong to class instead of specific instance.

OOPS CONCEPTS

Agenda:

Over view of OOPs principles


Classes and objects
Features of object orientation
o Encapsulation
o Inheritance
o Polymorphism

OVERVIEW OF OOPs principles:


object oriented programming is a method which holds the collection of
objects having data field and member functions
object oriented programming can be easily upgraded
All oop languages provide mechanism that is used to implement the object
oriented model. They are encapsulation, inheritance, and polymorphism.
Class: A class is a template/blueprint for creating an object
Object:
1. What is object?
2. What is NOT object?
a. Everything is either an object or associated with object
b. None of the things in this world is not an object or associated with object.
3. Definition: An object is an entity that has
i. properties for identifying its state and for validations,
ii. methods for behavior/ functionality
iii. and events for depicting the change of state.
b. State of an object: data associated with object at given instance of
time.
c. Every object should have some functionality other-wise it is destroyed.
i. Student should listen to class
ii. Fan should revolve
iii. If the above objects doesnt do their respective function, we will
destroy that object.
d. Change of state: when an object is defined, as an entity having certain
properties, any kind of change in the value of property leads to change of
state.
e. Event: change in the state of an object is depicted to other object in the
form an event
i. When teacher broad casts to write , students pick pen and
then writes
ii. Click on button to enter into form
1. Change of state of button is communicated to form in the
form of event.
4. Every object will differ from other objects either by state or behavior
5. Objects has a life time- its created, used and destroyed.
Object Oriented Application:
It is a collection of related objects, communication with each other,
exchanging messages with each other in a controlled environment as per
rules of the business.

Ex: suppose take a class room


Objects: teacher, students, pen, fan, computer.
Collection of related objects: vehicle cannot in class room.
Communicate with each other: student communicates with pen, teacher
teaches to student
( exchanging messages)
Controlled environment as per rule: mobile is used to record class but
you cant use for chatting, you can talk to your friends about doubts but you
cannot chat.

Component:
A ready to used third party object can be called as a component. It can be
replaced without any changes in the application. A component is generally
used by a programmer as an object.
Ex: A projector in a class room is a third party object. We generally dont
build projector. It is readily available in market, we simply plug in it.
People who build projector generally build projector for several application
like watching movies, classrooms.
Loosely coupled objects are better than tightly couple objects i.e., the lesser the
information given to other objects the better it is as the object are loosely coupled
the dependencies are less and strong security.
Ex: we dont need to know wife, children name of teacher.
Technology behind the working of fan we dont need to know
Three feature of OOPs
Encapsulation
Inheritance
Polymorphism
ENCAPSULATION:
The process of binding data and behavior i.e., functionality of an object
within a secured and controlled environment is called encapsulation.
It keeps the data safe from outside code
This encapsulation principle is used to implement the information hiding i.e.
data abstraction
Data Abstraction: The process of exposing the essential data of an object to the
outside of the world and hiding the low level data of that object is called data
abstraction
The principle of data hiding helps the programmer to build secure programs
that do not disturb the code in other parts of program.
INHERITENCE:
The process of acquiring the existing functionality of parent and by new
added features and functionality by a child object is called inheritance.
Using inheritance redundant programs, programming codes can be
eliminated and the use of previously defined classes may be continued.

Inheritance decreases the coding part of programmer


The advantage of inheritance is Generalization, Extensibility and Reusability.

Example: A calculator is a generalized form of mathematical operations whereas


scientific calculator is an extended and specific form
Some other examples: (child parent relation-ship)
Car and scooter are inherited to vehicle(car is a vehicle ; scooter is a
vehicle)
Teacher and students are inherited to person(teacher is a person; student is
a person)
Mango is a fruit
Chair is a furniture
KINDS OF RELATION SHIPS:
a. Is a depict inheritance two classes must be related
b. Type of/ instance of A class and object are related
c. Has a depicts containment two classes must be related.
POLYMORPHISM:
Poly means many and morph means form.
An object in different forms and in each form it exhibits same
functionality but implements in different ways.
A parent class variable taking the form of child class objects and using this
variable invoking the functionality of object this variable has actually taken
the form (either of child class object).
Examples:
A teacher can take the form of sport teacher or language teacher and in
both the forms it has the functionality teach, but the implementation of the
teach varies in both the objects.
Vehicle car or scooter drive
Phone mobile or landline speak
Database oracle or sqlserver write
Figure circle or square - area

Vous aimerez peut-être aussi