0% found this document useful (0 votes)
61 views16 pages

Oopc Complete 01

This document provides an overview of an assignment for a research project on object-oriented programming concepts. It outlines the main topics that will be covered in the assignment, including an overview of OOP, the history of OOP, main features like inheritance and polymorphism, relationships between objects using IS-A and HAS-A relationships, encapsulation, overriding vs overloading, and references. The assignment content section lists sub-topics like abstraction, interfaces, and the differences between abstract classes and interfaces that will be discussed.

Uploaded by

Ligeons pvt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views16 pages

Oopc Complete 01

This document provides an overview of an assignment for a research project on object-oriented programming concepts. It outlines the main topics that will be covered in the assignment, including an overview of OOP, the history of OOP, main features like inheritance and polymorphism, relationships between objects using IS-A and HAS-A relationships, encapsulation, overriding vs overloading, and references. The assignment content section lists sub-topics like abstraction, interfaces, and the differences between abstract classes and interfaces that will be discussed.

Uploaded by

Ligeons pvt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

Java Institute for Advanced Technology

UNIT NAME: - OBJECT ORIENTED PROGRAMMING


CONCEPTS I
(Research on Object-Oriented Programming concepts) UNIT
ID: - H7DY 04
ASSIGNMENT ID: - H7DY 04/AS/01

NAME: - shyamal pushpakumara


SCN NO: - 207978752
NIC: - 200326611368

BRANCH: - Colombo Branch


OOPC RESEARCH ASSINGMENT 1
CONTENT

o OVERVIEW ABOUT THE OBJECT ORIENTED PROGRAMMING CONCEPT


o HISTORY OF THE OBJECT-ORIENTED PROGRAMMING CONCEPT

o MAIN FEATURES OF OBJECT-ORIENTED PROGRAMMING


CONCEPT
o RELATIONSHIPS BETWEEN OBJECTS USING IS-A AND HAS-A
RELATIONSHIPS
 IS-A RELATIONSHIP

 HAS-A RELATIONSHIP

o ASSOCIATION

o AGGREGATION

o COMPOSITION

o POLYMORPHISM

o ENCAPSULATION

o DIFFERANCE BETWEEN OVERRIDING AND OVERLOADING

o ABSTRACTION

o DIFFERANCE BETWEEN ABSTRACT CLASS AND INTERFACES


o REFERENCES

OVERVIEW ABOUT THE OBJECT ORIENTED PROGRAMMING

CONCEPT

Object-Oriented-Programming has one of the most influential developments in computer


programming, gaining widespread use in the 1980s. Originally heralded for its facility for
managing complexity in ever-growing software systems, OOP quickly developed its Owen.

HISTORY OF THE OBJECT ORIENTED PROGRAMMING CONCEPT

The Object-Oriented programming idea started in 1970s and early 1980s “Bjorn Striustrup”
integrated OOP into C language. After resulting language was called C++ and it became the
first OOP language to be widely used commercially. Early 1990s a group at Sun led by
“James Gosling” developed a simpler version of C++ called Java that was meant to be
programming language for video-on-demand applications. Re-oriented this project focused in
Java as a language for programming Internet applications.

MAIN FEATURES OF OBJECT ORIENTED PROGRAMMING


CONCEPT

o IS-A Relationship

o HAS-A relationship

 Association

 Aggregation

 Composition

o Polymorphism

o Abstraction

o Encapsulation

o Association

o Overloading - Same name different parameter list

o Overriding - Deferent class same parameter list

o Interfaces

o Abstract class

RELATIONSHIPS BETWEEN OBJECTS USING IS-A AND HAS-A


RELATIONSHIPS

IS-A RELATIONSHIP
The concept of IS-A relationship in object oriented programing concept totally based
on inheritance, which can be of two types class inheritance or interface inheritance. For
example to IS-A relation using inheritance like “Animal and cat” or “Fruit and mango”, Cat
is an animal but Animal is not a cat, Mango is a fruit but Fruit is not a mango. It’s just saying
“A is a B type of things”.
Code example

1. Class BMW {

Class Vehicles {

int color note = 100;


String name = white”;
}

Class BMW extends vehicles {

public static void main (String args[]){

}}

class vehicles {

int color note = 100;


String name = white”;
}
HAS-A RELATIONSHIP
HAS-A means an instance of one class “has a” reference to an instance of another class or another
instance of same class. There have three main types of HAS-A relationship Association, Aggregation
and Composition. We can use explain HAS-A relationship to “Driver and Key” example.

Code example

package relationships;
class Car {
// Methods implementation and class/Instance members
private String color;
private int maxSpeed;
public void carInfo(){
System.out.println("Car Color= "+color + " Max Speed= " + maxSpeed);
}
public void setColor(String color) {
this.color = color;
}
public void setMaxSpeed(int maxSpeed) {
this.maxSpeed = maxSpeed;
}
}
This code example Key object is in to the Driver object and wants to access the Key object you
need to use the Driver object.
ASSOCIATION

Association is a relationship between two objects. In other words, association defines


the multiplicity between objects. One to one, many to one, one to many and many to many all
these words define an association between objects, all objects have their own lifecycle and
there is no owner. Association special form is Aggregation.

Ex-:

o Multiple under graduates can associate with single lecturer and single under graduate
can associate with multiple lecturers, but there have no ownership between the objects
and both have their own lifecycle. Both can create and delete independently.

AGGREGATION

Aggregation is special case of association. A directional association between objects


when an object “has-a” another object, then use the between them got an aggregation.
Explain the Aggregation we can use the “Room and Cloth rack”, Room has a Rack.

Code example

1. class Room {

private Rack rack;

void set Rack (Rack rack){


this.rack = rack;
}}

class Rack {

class check{
public static void main(String args[]){
Room room = new Room();
Rack newrack = new rack();

}}

COMPOSITION

Aggregation again specialize form is Composition. Composition calls have a ‘death’


relationship. It’s very strong type of Aggregation. This type child object does not have their
lifecycle and if parent object deleted, all child object are ‘death’. Explain that type we can use
Example of “Building and Roof”, if Building object destroy the Roof also can’t survive.

Code example

1. class Building {

Roof roof;

Public Building()
{ This.roof = new
Roof();
}}

class Roof {

Class Wood {

public static void main(String args[]){


Building b = new building();
}}
POLYMORPHISM

Polymorphism is a key concept in Object-Oriented Programming and is closely


related to inheritance. Because inheritance models an “is-a” relationship, one instance can
take on the behaviors and attributes of more than one class. According to the class hierarchy
of the person example, a Master is a graduate, a Graduate is a student, and a Student is a
person, so depending on the particular functionality desired, java might consider a particular
Master instance as a Master, a Graduate, a Student, or a Person, because, after all, a Master is
still a Person. There have two examples in the polymorphism concept, Static binding and
Dynamic binding.

Static binding

Polymorphism applies so instances rather than to classes, so static methods can be


bound to their implementations at compile time. This is referred to as static binding or
compile- time binding.

Dynamic binding

Dynamic binding, also called virtual method invocation, is the binding used for
instance methods to allow for polymorphism. Dynamic binding, as opposed to static binding,
means that the binding of instance methods to the appropriate implementation is resolved at
runtime, based on the instance and its type.

ENCAPSULATION

Encapsulation is one of the four fundamental OOP concepts. The other three
are inheritance, polymorphism and abstraction. Encapsulation is the technique of making the
fields in a class private and providing access to the fields via public methods. If a field is
declared private, it can’t access anyone in outside of the class. For this reason, encapsulation
is also referred to as data hiding, data immutability and data validation.
Code example

1. class A {
private int balance = 2000;
private String name = “Kamal”;
}
class B {
public static void main(String args[]){
A a = new A();
}}

This code example “class A” is a private class, “class B” can’t create a new object to class A,
because class A is private.

Encapsulation helps to create code that is loosely coupled. Because details are hidden, it
reduces the ability of other objects to directly modify an object’s state and behavior.

Encapsulation can,

o The fields of a class can be made read-only or write-only.


o The class users do not know how the stores its data, class can change
the data type of field and users of class don’t need to change their
codes.
o Class can have total control over what is stored in the class fields.
2. Class Acc{
private int balance;
String name;
Public int getBalance(){
return balance;
}
Public void setBalance(int balance){
this.balance = balance;
}}
DIFFARANCE BETWEEN OVERRIDING AND OVERLOADING

Overriding

1. Overriding happens at runtime. The binding of overridden method call to it’s happens
at runtime.
2. Static methods cannot be overridden, even declare a same static method in child class
it has nothing to do with the same method of parent class.
3. Dynamic binding is being used for overriding methods.

4. The reason is that the binding of overridden methods is being done at runtime.

5. Argument list should be same in method overriding.

6. Method overriding can have more specific return types.

Overloading

1. Overlarding happens at compile-time. The binding of overloaded method call to its


definition has happens at compile-time.
2. Static methods can be overloaded which means a class can have more than one static
method of same name.
3. Static binding is being used for overloaded methods.

4. Overlarding gives better performance compared to overriding.

5. Private and final methods can be overloaded but they cannot be overridden.

6. Argument list should be different while doing method overloading.

7. Return type of method does not matter in case of method overloading, it can be same
or different.
Code example for method Overriding

class animal{

public void eat()


{
System.out.println("animal is eating");
}
}
class dog extends animal{
//Overriding method
public void eat(){
System.out.println("dog is eating");
}
public static void main( String args[]) {
dog obj = new dog();
obj.eat();
}
}
This code example “Father” is a super class, “Son” is a subclass. class Son extends the
class Father and override two methods in class Son.

Code example for method Overloading

class Adder{  
static int add(int a,int b){return a+b;}
static int add(int a,int b,int c){return a+b+c;}
}
class TestOverloading1{
public static void main(String[] args){
System.out.println(Adder.add(11,11));
System.out.println(Adder.add(11,11,11));
}}
ABSTRACTION

Abstraction in OOP is a way to segregate implementation from interface,


Encapsulation, Inheritance, Polymorphism, Class and Object. Abstraction in java is achieved
by using interface and abstract class in java. Abstract class can contain both abstract and
concrete method. Abstract method doesn’t have body, just declaration. We won’t to use
interfaces or abstract class we need to extend and implement abstract methods with concrete
behavior.

DIFFARANCE BETWEEN ABSTRACT CLASS AND INTERFACES

Abstract classes

1. Abstract class can have abstract and non-abstract methods (implemented methods).

2. Abstract class doesn’t support multiple inheritances.

3. Abstract class can have static, non-static, final and non-final variables.

4. Abstract class can have static methods, main method and constructor.

5. Abstract class can provide the implementation of interfaces.


6. The abstract keyword is use to declare abstract class.
Interfaces

1. Interface can have only abstract methods.

2. Interface supports multiple inheritances.

3. Interface has only static and final variables.

4. Interface can’t have static methods, main method or constructor.

5. Interface can’t provide the implementation of abstract class.

6. The interface keyword use is used to declare interface.


REFERENCES

BOOK NAME

 Beginning Java Programming

CHAPTER

 Chapter - 7, Delving Further into Object-Oriented Concepts

ARTICLE

 Overloading Methods, Page-222

 Method Overriding, Page-243

 Polymorphism, Page-244

 Abstract Class and Methods, Page-246

 Interfaces, Page-252

AUTHORS

 Professor Bart Baesens- professor at KU Leuven (Belgium), lecturer at the


Southampton univercity (United Kingdom)
 Aimee Backiel- PhD researcher in applied economics at KU Leuven in Belgium

 Seppe Vanden Broucke- PhD researcher in the Department of Decision Sciences


and information Management at KU Leuven

You might also like