(Object Oriented Programming Structure) : Amity Institute of Information Technology
(Object Oriented Programming Structure) : Amity Institute of Information Technology
OOPS
(Object Oriented Programming Structure)
OOPS stands for Object Oriented Programming Structure.
Object Oriented Programming develops a program around
its data and sets of well-defined interface to that data.
11/26/2021 1
Amity Institute of Information Technology
•
CONCEPTS OF OOPS
Objects
• Classes
• Encapsulation
• Data Abstraction
• Inheritance
• Polymorphism
11/26/2021 2
Amity Institute of Information Technology
Objects
Object=Data+Method
11/26/2021 3
Amity Institute of Information Technology
Classes
11/26/2021 4
Amity Institute of Information Technology
Encapsulation
Encapsulation is the mechanism that binds together code and
the data.
11/26/2021 5
Amity Institute of Information Technology
Data Abstraction
• The act of representing essential features without including the background
details or explanations.
• Classes use the concept of abstraction and defined as a list of attributes, and
functions to operate these attributes.
11/26/2021 6
Amity Institute of Information Technology
Inheritance
Inheritance is the process by which objects of one
class acquires the properties of objects of another class.
Mammal Reptile
Dog
Cat
11/26/2021 7
Amity Institute of Information Technology
Polymorphism
Polymorphism is a feature that allows one
interface to be used for a general class of actions
or
“one interface, multiple methods”
Shape
Draw ()
Benefits of OOP
• Software reusability
•
• Code sharing
• Rapid prototyping
• Information hiding
11/26/2021 9
Amity Institute of Information Technology
Java Versions
Answer: No one person can learn the entire library – it is too large.
Amity Institute of Information Technology
public
{ publicclass HelloPrinter
{ static void main(String[] args)
// Display a greeting in the console window
System.out.println(“Hello,World”);
}
Amity Institute of Information Technology
In Java, every source file can contain, at most one public class.
The name of the public class must match the name of the file containing
the class:
Class HelloPrinter must be contained in a file named HelloPrinter.java
Amity Institute of Information Technology
System.out.println("Hello, World!");
Hello, World!
Amity Institute of Information Technology
A method call:
System.out.println("Hello, World!");
Java Program
Amity Institute of Information Technology
"Hello, World!"
Amity Institute of Information Technology
Hello
World!
How would you modify the HelloPrinter program to print the word "Hello" vertically?
Answer:
System.out.println("H");
System.out.println("e");
System.out.println("l");
System.out.println("l");
System.out.println("o");
Amity Institute of Information Technology
Answer:
System.out.println("Hello");
System.out.println("");
System.out.println("World");
Hello
a b l an k l i n e
World
Amity Institute of Information Technology
Errors
System.ou.println("Hello, World!");
System.out.println("Hello, Word!");
Amity Institute of Information Technology
"Division by zero"
Amity Institute of Information Technology
Locate the first marble that is preceded by a marble of a different color, and switch them.