Object Oriented
Programming
Learning Outcome
● On successful completion of this module,
○ Explain the fundamentals of Object-Oriented Programming concepts
○ Design Object-Oriented based applications
○ Develop Object-Oriented applications
Lesson -1 : fundamentals of Object-Oriented
Programming
Toady’s Aim
● Explain the fundamentals of Object-Oriented Programming
○ Understand and describe OOP
○ Understand and describe OOP concepts
■ Inheritance
■ Aptraction
■ Encapsulation
■ Polymorphism
Good Programming
● more code not necessarily a good thing
● measure good programmers by the amount of functionality
● code can be used many times but only has to be debugged once!
● Code should be
○ often self-contained
○ used to break up code
○ intended to be reusable
○ keep code organized
○ keep code coherent
Problem to Solution
Object:
● A specific real world entity
● Objects have all the attributes specified in the class definition
● An object is an instance of a concept
○ 1234 is an instance of an int
○ "hello" is an instance of a string
Class:
● Specifies the characteristics of an entity but is not an instance of that entity
● A class is a blueprint or template that defines the structure of the object.
Format:
public class <name of class>
{
attributes
methods
}
Example:
public class Employee {
private int name; // Attribute - stores the name of the employee
public void sayName() // Method - prints the name of the employee
{
System.out.println("My name is " + name);
}
}
Activity: What is the value of X?
public class Calculator{
int x = 10;
public static void main(String[] args) {
Calculator myObj = new Calculator();
myObj.x = 25; // x is now 25
System.out.println(myObj.x);
}
}
Attributes
Method
Object
○ Inheritance
○ Abstraction
○ Encapsulation
○ Polymorphism
What are the Concepts in OOP?
Inheritance
● Inheritance is a fundamental concept in object-oriented programming (OOP)
that allows a class to inherit properties and behaviors from another class.
● Inheritance represents the IS-A relationship which is also known as a parent-
child relationship
● It enables code reuse and promotes the organization and hierarchy of classes.
○ Sub Class/Child Class: Subclass is a class which inherits the other class. It is also called a
derived class, extended class, or child class.
○ Super Class/Parent Class: Superclass is the class from where a subclass inherits the features. It
is also called a base class or a parent class.
Real world example of inheritance
Example of inheritance
class Employee{
float salary=80000;
}
class Programmer extends Employee{
int bonus=30000;
public static void main(String args[]){
Programmer p=new Programmer();
System.out.println("Programmer salary is:"+p.salary);
System.out.println("Bonus of Programmer is:"+p.bonus);
}
}
Activity
● Identify the differences between all 5 types of the inheritance ?
● Find the examples for each type of inheritance?
Types of the inheritance
Encapsulation
● "sensitive" data is hidden from users
● way of hiding the implementation details of a class from outside access and
only exposing a public interface that can be used to interact with the class.
● encapsulation is achieved by declaring the instance variables of a class as
private,
class Person {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) { this.age = age; }
}
public class Display{
public static void main(String[] args)
{
Person person = new Person();
person.setName("John");
person.setAge(30);
System.out.println("Name: " + person.getName());
System.out.println("Age: " + person.getAge());
}
}
Activity
● Find the Access Modifier?
Are we achieved our aim?
○ Understand, identify and describe Classes, Objects, Properties and Methods
○ Understand and describe OOP concepts
■ Inheritance
■ Encapulation
Reference

Object Oriented Programming

  • 1.
  • 2.
    Learning Outcome ● Onsuccessful completion of this module, ○ Explain the fundamentals of Object-Oriented Programming concepts ○ Design Object-Oriented based applications ○ Develop Object-Oriented applications
  • 3.
    Lesson -1 :fundamentals of Object-Oriented Programming
  • 4.
    Toady’s Aim ● Explainthe fundamentals of Object-Oriented Programming ○ Understand and describe OOP ○ Understand and describe OOP concepts ■ Inheritance ■ Aptraction ■ Encapsulation ■ Polymorphism
  • 5.
    Good Programming ● morecode not necessarily a good thing ● measure good programmers by the amount of functionality ● code can be used many times but only has to be debugged once! ● Code should be ○ often self-contained ○ used to break up code ○ intended to be reusable ○ keep code organized ○ keep code coherent
  • 7.
  • 9.
    Object: ● A specificreal world entity ● Objects have all the attributes specified in the class definition ● An object is an instance of a concept ○ 1234 is an instance of an int ○ "hello" is an instance of a string
  • 10.
    Class: ● Specifies thecharacteristics of an entity but is not an instance of that entity ● A class is a blueprint or template that defines the structure of the object.
  • 11.
    Format: public class <nameof class> { attributes methods } Example: public class Employee { private int name; // Attribute - stores the name of the employee public void sayName() // Method - prints the name of the employee { System.out.println("My name is " + name); } }
  • 12.
    Activity: What isthe value of X? public class Calculator{ int x = 10; public static void main(String[] args) { Calculator myObj = new Calculator(); myObj.x = 25; // x is now 25 System.out.println(myObj.x); } } Attributes Method Object
  • 13.
    ○ Inheritance ○ Abstraction ○Encapsulation ○ Polymorphism What are the Concepts in OOP?
  • 14.
    Inheritance ● Inheritance isa fundamental concept in object-oriented programming (OOP) that allows a class to inherit properties and behaviors from another class. ● Inheritance represents the IS-A relationship which is also known as a parent- child relationship ● It enables code reuse and promotes the organization and hierarchy of classes. ○ Sub Class/Child Class: Subclass is a class which inherits the other class. It is also called a derived class, extended class, or child class. ○ Super Class/Parent Class: Superclass is the class from where a subclass inherits the features. It is also called a base class or a parent class.
  • 15.
    Real world exampleof inheritance
  • 16.
    Example of inheritance classEmployee{ float salary=80000; } class Programmer extends Employee{ int bonus=30000; public static void main(String args[]){ Programmer p=new Programmer(); System.out.println("Programmer salary is:"+p.salary); System.out.println("Bonus of Programmer is:"+p.bonus); } }
  • 17.
    Activity ● Identify thedifferences between all 5 types of the inheritance ? ● Find the examples for each type of inheritance?
  • 18.
    Types of theinheritance
  • 19.
    Encapsulation ● "sensitive" datais hidden from users ● way of hiding the implementation details of a class from outside access and only exposing a public interface that can be used to interact with the class. ● encapsulation is achieved by declaring the instance variables of a class as private,
  • 20.
    class Person { privateString name; private int age; public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } } public class Display{ public static void main(String[] args) { Person person = new Person(); person.setName("John"); person.setAge(30); System.out.println("Name: " + person.getName()); System.out.println("Age: " + person.getAge()); } }
  • 21.
    Activity ● Find theAccess Modifier?
  • 22.
    Are we achievedour aim? ○ Understand, identify and describe Classes, Objects, Properties and Methods ○ Understand and describe OOP concepts ■ Inheritance ■ Encapulation
  • 23.