You are on page 1of 15

OOP FUNDAMENTALS

• What is OOP?  It stands for Object Oriented Programming • OOP treats data as a critical element in the program development and does not allow it to flow freely around the system. • It ties data more closely to the functions that operate on it, and protects it from accidental modification from outside functions. Everything in OOP is grouped as self sustainable "objects".

• What is an Object?
 An object can be considered a "thing" that can perform a set of related activities. The set of activities that the object performs defines the object's behavior.  For example, a Student (object) can give the name or address. In pure OOP terms an object is an instance of a class.

• What is a Class?

 A class is simply a representation of a type of object.  It is the blueprint/ plan/ template that describe the details of an object.  A class is the blueprint from which the individual objects are created.  Class is composed of three things: a name, attributes, and operations.

• What is Encapsulation (or information hiding)? • The wrapping up of data and functions into a single unit (called class) 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.

• What is Abstraction? • It refers to the act of representing essential features without including the background details or explanations. • It provides us to know the attribute and their values instead of how they were operated.

• What is Inheritance?  Ability of a new class to be created, from an existing class by extending it, is called inheritance.

 According to the above example the new class (IOException), which is called the derived class or subclass, inherits the members of an existing class (Exception), which is called the base class or superclass.  The class IOException can extend the functionality of the class Exception by adding new types and methods and by overriding existing ones.

• What is Polymorphisms?  Polymorphisms is a generic term that means 'many shapes'. More precisely Polymorphisms means the ability to request that the same operations be performed by a wide range of different types of things.

OBJECT AND CLASSES IN JAVA
• Class implementation  Classes are the fundamental building blocks of Java programs. Defining a class is basically a matter of specifying a name for the class, its relationship to other classes and what sort of behaviors the class exhibits as well as what data it may contain.

class student { } The word class above is called a keyword and can only be used to state that the following code is the definition of a class. The class keyword is immediately followed by the desired name of the class The curly braces, {...}, indicate the extent of the definition of the class. Definitions of the class's behaviors and data will be found between the curly braces

class student

{
string name; int rno; int m1,m2,m3,tot; student(string nam, int no) { name=nam; rno=no; } void setmarks(int ma1,int ma2,int ma3) { m1=ma1,m2=ma2,m3=ma3; tot=m1+m2+m3; } int gettotal() { return tot; } }

• Implementation of object  Objects are miniature programs that are complete with their own private copy of all internal data.  The designer of the object decides exactly how the object can be used .  Important here is, how the user interacts with the object.  user sends a message to an object and gets a reply .  message may result in the object changing state.

• • • •

student st1=new student(“arun”,10); st1.setmarks(56,70,90); total=st1.gettotal(); First comes st1 -the name, or identifier of the object.

 Next comes a dot. This is the member selection operator and is use to indicate which member (i.e. which bit) of the object you want to deal with.  Finally comes setmarks() , be called a member function .  Sending a message to an object means calling one of its member functions.  object will have a number of member functions that start “get" that simply return some information about its state. referred to collectively as "getters".  functions that start “set", that change state of the object.

• A Module Factory A class is rather like an object factory. Each time a new object is required it is created using the information in the class. The class holds the code shared by all of its objects. It also contains details of an object's internal data and this used to reserve space and initialise it when an object is brought into existence, a process called instantiation'.