SlideShare a Scribd company logo
O bject  o riented  p rogramming  java OOP  Understanding MOHAMMAD ALSHEHRI LS0806205
What is Object-Oriented Programming? Object oriented programming or OOP is a way of writing programs using objects.  {   An object is a data structure in memory that has      attributes and methods.  {   The attributes of an object are the same as variables    and the methods of an object are the same as    functions or procedures. The reason for using objects instead of the old procedural method of programming is because objects group the variables and methods about something together instead of keeping them all apart as in procedural programming
There are four main pillars of an OOP: ,[object Object],[object Object],[object Object],[object Object]
Inheritance provide the facility to drive one class by another using simple syntax. You can say that it is a process of creating new class and use the behavior of the existing class by extending them for reuse the existing code and adding the additional features as you need. It also use to manage and make well structured software. ,[object Object]
Encapsulation is the ability to bundle the property and method of the object and also operate them. It is the mechanism of combining the information and providing the abstraction as well. ,[object Object]
As the name suggest one name multiple form, Polymorphism is the way that provide the different functionality by the functions  having the same name based on the signatures of the methods. There are two type of polymorphism first is run-time polymorphism and second is compile-time polymorphism. ,[object Object]
It is the way that provide the maximum functionality to a program for a specific type at runtime. There are two type of binding first is dynamic binding and second is static binding.  ,[object Object]
[object Object]
First program in java ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object]
class  Check{   private int amount=0;    public int  getAmount(){      return amount;   }    public void  setAmount( int  amt){      amount=amt;   }  }  public class  Mainclass{    public static void  main(String[] args){      int amt=0;      Check obj=  new  Check();      obj.setAmount(200);      amt=obj.getAmount();       System.out.println("Your current amount is :"+amt);      } }
Using classes and objects Before you can create an object you need to create a class. A class is the code for an object and an object is the instance of a class in memory. When you create an object from a class it is called instantiating the object. To help you understand think of the plan for a house. The plan for the house is like the class and the house that will be built from the plan is the object.
Creating a class You have already been creating classes in the programs you have written so far. To show you how they work we will need to create a separate class in a separate file. This class will be called Student. public class Student { }
Now we will add 2 variables to the class which are the student's name and student number. public class Student {    String studentName;    int studentNumber; }
Next we must add methods for getting and setting these variables. public class Student {    String studentName;    int studentNumber;      public void setStudentName(String s)    {       studentName = s;    }      public void setStudentNumber(int i)    {       studentNumber = i;    }      public String getStudentName()    {       return studentName;    }      public int getStudentNumber()    {        return studentNumber;    } }
Instantiating an object Now that we have finished writing the class we must create the main program that will instantiate the object. We will call the main program class TestClass. It should look just like how every other java program starts off. public class TestClass {    public static void main(String[] args)    {    } }  Now we will instantiate the object. To do this we declare a reference to the object called stu and set it equal to a newly created object in memory. public class TestClass {    public static void main(String[] args)    {       Student stu = new Student();    } }
Using the object Now we can call the methods from the stu object to set the values of its variables. You can't set the values of the variables in an object unless they are declared as public. This makes it safer to work with variables because they can't be changed by mistake by another object. public class TestClass {    public static void main(String[] args)    {       Student stu = new Student();       stu.setStudentName("John Smith");       stu.setStudentNumber(12345);       System.out.println("Student Name: " + stu.getStudentName());       System.out.println("Student Number: " + stu.getStudentNumber());    } }
Constructors A constructor is a method that is run when an object is instantiated. Constructors are useful for initializing variables. The constructor is declared with only the name of the class followed by brackets. Here is an example of the Student class that initializes both student name and student number.
[object Object]
You can also pass parameters to a constructor when you instantiate an object. All you need to do is add the parameters in the brackets after the constructor declaration just like a normal method.
[object Object],[object Object]
Now all you need to do is put the parameters in the brackets when you instantiate the object in the main program. public class TestClass {    public static void main(String[] args)    {       Student stu = new Student("John Smith",12345);       System.out.println("Student Name: " + stu.getStudentName());       System.out.println("Student Number: " + stu.getStudentNumber());    } }
How to use inheritance We will first create a parent class called Person. We will then create a child class called Student. Then we will create a program to use the Student class. The following is a Person class which has a variable for the person's name. There are also set and get methods for the name. class Person {    private String name;      public void setName(String n)    {       name = n;    }      public String getName()    {       return name;    } }
Now we will create the Student class that has a variable for the student number and the get and set methods for student number. The extends keyword is used to inherit from the Person class in the following example. class Student extends Person {    private String stuNum;      public void setStuNum(String sn)    {       stuNum = sn;    }      public String getStuNum()    {       return stuNum;    } }
public class AnimalReference { public static void main(String args[]) Animal ref  // set up var for an Animal Cow aCow = new Cow("Bossy");  // makes specific objects Dog aDog = new Dog("Rover"); Snake aSnake = new Snake("Earnie"); // now reference each as an Animal ref = aCow; ref.speak(); ref = aDog; ref.speak(); ref = aSnake; ref.speak(); } Polymorphism
[object Object],[object Object],[object Object],中沙友谊地久天长
 

More Related Content

What's hot

Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc cs
KALAISELVI P
 
11 Using classes and objects
11 Using classes and objects11 Using classes and objects
11 Using classes and objects
maznabili
 
Oops in java
Oops in javaOops in java
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
kishu0005
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVAAbhilash Nair
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Tushar B Kute
 
Lecture 01 - Basic Concept About OOP With Python
Lecture 01 - Basic Concept About OOP With PythonLecture 01 - Basic Concept About OOP With Python
Lecture 01 - Basic Concept About OOP With Python
National College of Business Administration & Economics ( NCBA&E)
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
talha ijaz
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
Fajar Baskoro
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
Atul Sehdev
 
Object and class
Object and classObject and class
Object and class
mohit tripathi
 
Introduce oop in python
Introduce oop in pythonIntroduce oop in python
Introduce oop in python
tuan vo
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
Sohanur63
 
Python Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | EdurekaPython Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | Edureka
Edureka!
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
Praveen M Jigajinni
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Java
kjkleindorfer
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
Spotle.ai
 

What's hot (20)

Python unit 3 m.sc cs
Python unit 3 m.sc csPython unit 3 m.sc cs
Python unit 3 m.sc cs
 
11 Using classes and objects
11 Using classes and objects11 Using classes and objects
11 Using classes and objects
 
Oops in java
Oops in javaOops in java
Oops in java
 
Java oops PPT
Java oops PPTJava oops PPT
Java oops PPT
 
Classes, objects in JAVA
Classes, objects in JAVAClasses, objects in JAVA
Classes, objects in JAVA
 
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B KuteChapter 02: Classes Objects and Methods Java by Tushar B Kute
Chapter 02: Classes Objects and Methods Java by Tushar B Kute
 
Lecture 01 - Basic Concept About OOP With Python
Lecture 01 - Basic Concept About OOP With PythonLecture 01 - Basic Concept About OOP With Python
Lecture 01 - Basic Concept About OOP With Python
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Lect 1-class and object
Lect 1-class and objectLect 1-class and object
Lect 1-class and object
 
ITFT-Classes and object in java
ITFT-Classes and object in javaITFT-Classes and object in java
ITFT-Classes and object in java
 
Object and class
Object and classObject and class
Object and class
 
Introduce oop in python
Introduce oop in pythonIntroduce oop in python
Introduce oop in python
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Java class,object,method introduction
Java class,object,method introductionJava class,object,method introduction
Java class,object,method introduction
 
Java basic
Java basicJava basic
Java basic
 
Python Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | EdurekaPython Class | Python Programming | Python Tutorial | Edureka
Python Class | Python Programming | Python Tutorial | Edureka
 
Chapter 07 inheritance
Chapter 07 inheritanceChapter 07 inheritance
Chapter 07 inheritance
 
Java Basic day-2
Java Basic day-2Java Basic day-2
Java Basic day-2
 
Week9 Intro to classes and objects in Java
Week9 Intro to classes and objects in JavaWeek9 Intro to classes and objects in Java
Week9 Intro to classes and objects in Java
 
Class and Objects in Java
Class and Objects in JavaClass and Objects in Java
Class and Objects in Java
 

Similar to Oop

Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
ssuser8347a1
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
madhavi patil
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
ilias ahmed
 
Introduction to java programming
Introduction to java programmingIntroduction to java programming
Introduction to java programming
shinyduela
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
CPD INDIA
 
Sonu wiziq
Sonu wiziqSonu wiziq
Sonu wiziq
Sonu WIZIQ
 
Static keyword.pptx
Static keyword.pptxStatic keyword.pptx
Static keyword.pptx
KishanMishra44
 
Linq
LinqLinq
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
Sagar Verma
 
Oop java
Oop javaOop java
Oop java
Minal Maniar
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
mha4
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
mha4
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
BG Java EE Course
 
Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes
Uzair Salman
 
11.Object Oriented Programming.pdf
11.Object Oriented Programming.pdf11.Object Oriented Programming.pdf
11.Object Oriented Programming.pdf
Export Promotion Bureau
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
Gousalya Ramachandran
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
Madishetty Prathibha
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
Shalabh Chaudhary
 

Similar to Oop (20)

Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
 
Introduction to java programming
Introduction to java programmingIntroduction to java programming
Introduction to java programming
 
oops concept in java | object oriented programming in java
oops concept in java | object oriented programming in javaoops concept in java | object oriented programming in java
oops concept in java | object oriented programming in java
 
Sonu wiziq
Sonu wiziqSonu wiziq
Sonu wiziq
 
Static keyword.pptx
Static keyword.pptxStatic keyword.pptx
Static keyword.pptx
 
Linq
LinqLinq
Linq
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
Oop java
Oop javaOop java
Oop java
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots03 object-classes-pbl-4-slots
03 object-classes-pbl-4-slots
 
Defining classes-and-objects-1.0
Defining classes-and-objects-1.0Defining classes-and-objects-1.0
Defining classes-and-objects-1.0
 
JavaScript OOP
JavaScript OOPJavaScript OOP
JavaScript OOP
 
Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes Object Oriented Programming using JAVA Notes
Object Oriented Programming using JAVA Notes
 
11.Object Oriented Programming.pdf
11.Object Oriented Programming.pdf11.Object Oriented Programming.pdf
11.Object Oriented Programming.pdf
 
Object oriented concepts
Object oriented conceptsObject oriented concepts
Object oriented concepts
 
Lecture 2 classes i
Lecture 2 classes iLecture 2 classes i
Lecture 2 classes i
 
Classes objects in java
Classes objects in javaClasses objects in java
Classes objects in java
 
OOPs & Inheritance Notes
OOPs & Inheritance NotesOOPs & Inheritance Notes
OOPs & Inheritance Notes
 

Recently uploaded

Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
UiPathCommunity
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
ViralQR
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 

Recently uploaded (20)

Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.Welocme to ViralQR, your best QR code generator.
Welocme to ViralQR, your best QR code generator.
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 

Oop

  • 1. O bject o riented p rogramming java OOP Understanding MOHAMMAD ALSHEHRI LS0806205
  • 2. What is Object-Oriented Programming? Object oriented programming or OOP is a way of writing programs using objects. { An object is a data structure in memory that has attributes and methods. { The attributes of an object are the same as variables and the methods of an object are the same as functions or procedures. The reason for using objects instead of the old procedural method of programming is because objects group the variables and methods about something together instead of keeping them all apart as in procedural programming
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11. class  Check{   private int amount=0;   public int  getAmount(){      return amount;   }   public void  setAmount( int  amt){      amount=amt;   }  } public class  Mainclass{   public static void  main(String[] args){      int amt=0;      Check obj=  new  Check();      obj.setAmount(200);      amt=obj.getAmount();       System.out.println("Your current amount is :"+amt);      } }
  • 12. Using classes and objects Before you can create an object you need to create a class. A class is the code for an object and an object is the instance of a class in memory. When you create an object from a class it is called instantiating the object. To help you understand think of the plan for a house. The plan for the house is like the class and the house that will be built from the plan is the object.
  • 13. Creating a class You have already been creating classes in the programs you have written so far. To show you how they work we will need to create a separate class in a separate file. This class will be called Student. public class Student { }
  • 14. Now we will add 2 variables to the class which are the student's name and student number. public class Student {    String studentName;    int studentNumber; }
  • 15. Next we must add methods for getting and setting these variables. public class Student {    String studentName;    int studentNumber;      public void setStudentName(String s)    {       studentName = s;    }      public void setStudentNumber(int i)    {       studentNumber = i;    }      public String getStudentName()    {       return studentName;    }      public int getStudentNumber()    {        return studentNumber;    } }
  • 16. Instantiating an object Now that we have finished writing the class we must create the main program that will instantiate the object. We will call the main program class TestClass. It should look just like how every other java program starts off. public class TestClass {    public static void main(String[] args)    {    } } Now we will instantiate the object. To do this we declare a reference to the object called stu and set it equal to a newly created object in memory. public class TestClass {    public static void main(String[] args)    {       Student stu = new Student();    } }
  • 17. Using the object Now we can call the methods from the stu object to set the values of its variables. You can't set the values of the variables in an object unless they are declared as public. This makes it safer to work with variables because they can't be changed by mistake by another object. public class TestClass {    public static void main(String[] args)    {       Student stu = new Student();       stu.setStudentName("John Smith");       stu.setStudentNumber(12345);       System.out.println("Student Name: " + stu.getStudentName());       System.out.println("Student Number: " + stu.getStudentNumber());    } }
  • 18. Constructors A constructor is a method that is run when an object is instantiated. Constructors are useful for initializing variables. The constructor is declared with only the name of the class followed by brackets. Here is an example of the Student class that initializes both student name and student number.
  • 19.
  • 20. You can also pass parameters to a constructor when you instantiate an object. All you need to do is add the parameters in the brackets after the constructor declaration just like a normal method.
  • 21.
  • 22. Now all you need to do is put the parameters in the brackets when you instantiate the object in the main program. public class TestClass {    public static void main(String[] args)    {       Student stu = new Student("John Smith",12345);       System.out.println("Student Name: " + stu.getStudentName());       System.out.println("Student Number: " + stu.getStudentNumber());    } }
  • 23. How to use inheritance We will first create a parent class called Person. We will then create a child class called Student. Then we will create a program to use the Student class. The following is a Person class which has a variable for the person's name. There are also set and get methods for the name. class Person {    private String name;      public void setName(String n)    {       name = n;    }      public String getName()    {       return name;    } }
  • 24. Now we will create the Student class that has a variable for the student number and the get and set methods for student number. The extends keyword is used to inherit from the Person class in the following example. class Student extends Person {    private String stuNum;      public void setStuNum(String sn)    {       stuNum = sn;    }      public String getStuNum()    {       return stuNum;    } }
  • 25. public class AnimalReference { public static void main(String args[]) Animal ref // set up var for an Animal Cow aCow = new Cow("Bossy"); // makes specific objects Dog aDog = new Dog("Rover"); Snake aSnake = new Snake("Earnie"); // now reference each as an Animal ref = aCow; ref.speak(); ref = aDog; ref.speak(); ref = aSnake; ref.speak(); } Polymorphism
  • 26.
  • 27.