SlideShare a Scribd company logo
OOPs CONCEPTS FORANDROIDPROGRAMMING
OBJECT ORIENTED PROGRAMMING system
Purvik Rana
intro
 A programming paradigm where everything is represented as
• an object.
 A methodology to design a program using
• Classes and Objects .
 Simplifies the software development process & maintenance by rich
concepts like
• Object • Polymorphism
• Class • Abstraction
• Inheritance • Encapsulation
Intro- continue
 Object
• Entity that has State (Property) and Behaviours (Methods).
• For Example: Person, Car, House, Chair.
 Class
• Collection of Objects ( a logical entity ).
 Inheritance
• When one object acquires all the properties & behaviours of parent object 
provides code Reusability.
 Polymorphism
• Where one task perform in different ways (overloading & overriding).
Intro- continue
 Abstraction
• Hiding internal details and display only functionality.
• It is achieved through Abstract class & Interface.
 Encapsulation
• Binding Code and Data together into a single unit.
• A Java Class is an example of it where all the data members and methods are
private to it.
NamingConventions
Name Convention
class name
should start with uppercase letter and be a noun e.g. String, Color, Button, System,
Thread etc.
interface name
should start with uppercase letter and be an adjective e.g. Runnable, Remote,
ActionListener etc.
method name
should start with lowercase letter and be a verb e.g. actionPerformed(), main(), print(),
println() etc.
variable name should start with lowercase letter e.g. firstName, orderNumber etc.
package name should be in lowercase letter e.g. java, lang, sql, util etc.
constants name should be in uppercase letter. e.g. RED, YELLOW, MAX_PRIORITY etc.
CamelCase : If name is combined with two words, second word will start with uppercase letter
always
ClassDeclaration
class Student1{
int id; // data member (also instance variable)
String name; // data member(also instance variable)
public static void main(String args[]){
Student1 s1 = new Student1(); // creating an object of Student
System.out.println(s1.id); // accessing class data member
System.out.println(s1.name);
}
}
MethodOverloading
 What
• Class has method with same name but with different parameters.
• Increase readability of the program.
 Two ways to perform:
• Either change the number of arguments.
• Change the data type of arguments.
• Not possible by changing the return type of method.
Methodoverloading - Example
Example-1 Different No of Parameters
class Calculation{
void sum(int a,int b)
{System.out.println(a+b);}
void sum(int a,int b,int c)
{System.out.println(a+b+c);}
public static void main(String args[]){
Calculation obj=new Calculation();
obj.sum(10,10,10);
obj.sum(20,20);
} }
Example -2 Changing Data type
class Calculation2{
void sum(int a,int b)
{System.out.println(a+b);}
void sum(double a,double b)
{System.out.println(a+b);}
public static void main(String args[]){
Calculation2 obj=new Calculation2();
obj.sum(10.5,10.5);
obj.sum(20,20);
} }
Constructor
 What
• Special type of method used to initialize the object.
• Invoked at the time of object creation.
 Rules
• Name must be same as its class name.
• Must have no explicit return type.
 Type
• Default Constructor.
• Parameterized Constructor.
 Constructor Overloading
• Same as method overloading
Constructor - example
class Student5{
int id;
String name;
int age;
Student5() { } // default
Student5(int i,String n){
id = i;
name = n; }
Student5(int i,String n,int a){
id = i;
name = n;
age=a;
}
void display(){
System.out.println(id+" "+name+" "+age);}
public static void main(String args[]){
Student5 s1 = new Student5(111,"Karan");
Student5 s2 = new Student5(222,"Aryan",25);
s1.display();
s2.display();
}
}
Inheritance
 What
• One object acquires all the properties & behaviours of parent object.
• Reuse parameters and method of parent class.
• Holds IS-A relationship.
 Why
• Method Overriding (For run time polymorphism)
• Code reusability
class Subclass-name extends Superclass-name
{
//methods and fields
}
Inheritance - continue
 Types
• Multiple inheritance not supported
in Java through Classes
• Supported through “Interfaces”
Inheritance- example
class Employee{
float salary=40000;
}
class Programmer extends Employee{
int bonus=10000;
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);
}
}
Aggregation
 When class has an entity reference  called Aggregation.
 Why  for code reusability.
class Employee{
int id;
String name;
Address address; //Address is nothing but some other class
...
}
 Relationship is : Employee HAS-A address.
 Used when there is no IS-A relationship.
MethodOverriding
 When subclass override same method as declared in Super Class.
 Usage
• Subclass provides specific implementation of method that it overrides.
• Used for runtime polymorphism.
 Rules
• Method must have same name as the parent class
• Must have same parameter as the parent class
• Must be a IS-A relationship
Methodoverriding- Example
Example
class Bank{
int getRateOfInterest(){return 0;}
}
class SBI extends Bank{
int getRateOfInterest(){return 8;}
}
class ICICI extends Bank{
int getRateOfInterest(){return 7;}
}
AbstractClass
 What
• Class declared with Abstract keyword.
• Can have abstract & non-abstract methods.
 Abstraction
• Used to hide implementation details from the user.
• Focus on “what it does” not reveal “how it does”.
 Two ways to achieve, thorough
• Abstract Class
• Interface
Abstractclass - CONTINUE
Example
abstract class Bike{
abstract void run();
}
class Honda4 extends Bike{
void run(){System.out.println("running safely..");}
public static void main(String args[]){
Bike obj = new Honda4();
obj.run();
}
}
Interface
 What
• Is a blueprint of a class and abstract methods only.
• Should have only abstract methods in Java interface.
• Parameters are public, static & final.
• Methods are public & abstract.
 Why
• To achieve full abstraction.
• To support multiple inheritance.
• To achieve loose coupling.
Interface-example-1
Understand Relationship
Example:
interface printable{
void print();
}
class A6 implements printable{
public void print()
{System.out.println("Hello");}
public static void main(String args[]){
A6 obj = new A6();
obj.print();
}
}
Interface-example-2
interface Printable{
void print(); }
interface Showable{
void show(); }
class A7 implements Printable,Showable{
public void print(){System.out.println("Hello");}
public void show(){System.out.println("Welcome");}
public static void main(String args[]){
A7 obj = new A7();
obj.print();
obj.show();
} }
encapsulation
 Wrapping code & data together. into a single unit
 Fully encapsulated class contain
• All data member as private.
• Use setter & getter method to set and get the data values.
 Advantages
• Make class read only or write only
• Provides control over the data
Encapsulation- example
//save as Student.java
public class Student{
private String name;
public String getName(){
return name;
}
public void setName(String name){
this.name=name
}
}
//save as Test.java
class Test{
public static void main(String[] args){
Student s=new Student();
s.setname("vijay");
System.out.println(s.getName());
}
}
superkeyword
 Is a reference variable used to refer immediate parent class object
 Usage
• To refer immediate parent class instance variable.
• To invoke immediate parent class constructor.
• To invoke immediate parent class method.
Superkeyword- example
Example - 1
class Vehicle{
int speed = 50;
}
class Bike4 extends Vehicle{
int speed = 100;
void display(){
System.out.println(super.speed);
//will print speed of Vehicle now
}
public static void main(String args[]){
Bike4 b = new Bike4();
b.display();
} }
Example - 2
class Vehicle{
Vehicle()
{System.out.println("Vehicle is created");}
}
class Bike5 extends Vehicle{
Bike5(){
super();
//will invoke parent class constructor
System.out.println("Bike is created");
}
public static void main(String args[]){
Bike5 b = new Bike5();
} }
Example – 3
class Person{
void message()
{System.out.println("welcome");}
}
class Student16 extends Person{
void message()
{System.out.println("welcome to java");}
void display(){
message();
//will invoke current class message() method
super.message();
//will invoke parent class message() method
}
public static void main(String args[]){
Student16 s=new Student16();
s.display();
} }
Thiskeyword
 Is a reference variable used to refer current objects
 Usage
• to refer current class instance variable
• to invoke current class constructor
• can be passed as an argument in the method call
• can be passed as argument in the constructor call
• can also be used to return the current class instance
Thiskeyword - example
Example - 1
class Student11{
int id;
String name;
Student11(int id,String name){
this.id = id;
this.name = name;
}
void display()
{ System.out.println(id+" "+name);}
public static void main(String args[]){
Student11 s1 = new Student11(111,"Karan");
Student11 s2 = new Student11(222,"Aryan");
s1.display();
s2.display();
} }
Example – 2
class Student13{
int id;
String name;
Student13()
{System.out.println("defaultconstructor is invoked");}
Student13(int id,String name){
this (); //it is used to invoked current class constructor.
this.id = id;
this.name = name; }
void display(){System.out.println(id+" "+name);}
public static void main(String args[]){
Student13 e1 = new Student13(111,"karan");
Student13 e2 = new Student13(222,"Aryan");
e1.display();
e2.display();
} }
THIS IS WHATALLWE’VE LEARN
• OBJECT & CLASS
• INHERITANCE
• ABSTRACTION
• ENCAPSULATION
• POLYMORPHISM
• Super & This Keyword
SE CONCEPTS FORANDROIDPROGRAMMING
Next Session
Ad

More Related Content

What's hot (20)

Core Java Slides
Core Java SlidesCore Java Slides
Core Java Slides
Vinit Vyas
 
Reflection in java
Reflection in javaReflection in java
Reflection in java
upen.rockin
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
Sandeep Rawat
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Android
ma-polimi
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
Dominic Arrojado
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
Tanmoy Barman
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
Dzmitry Naskou
 
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Edureka!
 
Generics in java
Generics in javaGenerics in java
Generics in java
suraj pandey
 
Java Basics
Java BasicsJava Basics
Java Basics
shivamgarg_nitj
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
Amit Soni (CTFL)
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
foreverredpb
 
PROGRAMMING IN JAVA unit 1.pptx
PROGRAMMING IN JAVA unit 1.pptxPROGRAMMING IN JAVA unit 1.pptx
PROGRAMMING IN JAVA unit 1.pptx
SeethaDinesh
 
Java program structure
Java program structure Java program structure
Java program structure
Mukund Kumar Bharti
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java Servlet
Fahmi Jafar
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
arvind pandey
 
Spring Core
Spring CoreSpring Core
Spring Core
Pushan Bhattacharya
 
Polymorphism in oop
Polymorphism in oopPolymorphism in oop
Polymorphism in oop
MustafaIbrahimy
 
Core Java Slides
Core Java SlidesCore Java Slides
Core Java Slides
Vinit Vyas
 
Reflection in java
Reflection in javaReflection in java
Reflection in java
upen.rockin
 
Introduction to java
Introduction to java Introduction to java
Introduction to java
Sandeep Rawat
 
Intents in Android
Intents in AndroidIntents in Android
Intents in Android
ma-polimi
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
Tanmoy Barman
 
Spring Framework - AOP
Spring Framework - AOPSpring Framework - AOP
Spring Framework - AOP
Dzmitry Naskou
 
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Java Tutorial | Java Programming Tutorial | Java Basics | Java Training | Edu...
Edureka!
 
Introduction to Spring Framework
Introduction to Spring FrameworkIntroduction to Spring Framework
Introduction to Spring Framework
Serhat Can
 
Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...Introduction to Java Programming, Basic Structure, variables Data type, input...
Introduction to Java Programming, Basic Structure, variables Data type, input...
Mr. Akaash
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
Amit Soni (CTFL)
 
Object Oriented Programming with C#
Object Oriented Programming with C#Object Oriented Programming with C#
Object Oriented Programming with C#
foreverredpb
 
PROGRAMMING IN JAVA unit 1.pptx
PROGRAMMING IN JAVA unit 1.pptxPROGRAMMING IN JAVA unit 1.pptx
PROGRAMMING IN JAVA unit 1.pptx
SeethaDinesh
 
Knowledge Sharing : Java Servlet
Knowledge Sharing : Java ServletKnowledge Sharing : Java Servlet
Knowledge Sharing : Java Servlet
Fahmi Jafar
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
arvind pandey
 

Similar to OOPs Concepts - Android Programming (20)

Introduction to java programming
Introduction to java programmingIntroduction to java programming
Introduction to java programming
shinyduela
 
11.Object Oriented Programming.pdf
11.Object Oriented Programming.pdf11.Object Oriented Programming.pdf
11.Object Oriented Programming.pdf
Export Promotion Bureau
 
oops with java modules i & ii.ppt
oops with java modules i & ii.pptoops with java modules i & ii.ppt
oops with java modules i & ii.ppt
rani marri
 
inheritance, Packages and Interfaces.pptx
inheritance, Packages and Interfaces.pptxinheritance, Packages and Interfaces.pptx
inheritance, Packages and Interfaces.pptx
Vanitha Alagesan
 
Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \
Pritom Chaki
 
Inheritance1
Inheritance1Inheritance1
Inheritance1
Daman Toor
 
OOP with Java - Part 3
OOP with Java - Part 3OOP with Java - Part 3
OOP with Java - Part 3
RatnaJava
 
Modules 333333333³3444444444444444444.pptx
Modules 333333333³3444444444444444444.pptxModules 333333333³3444444444444444444.pptx
Modules 333333333³3444444444444444444.pptx
radhikacordise
 
inheritance and interface in oops with java .pptx
inheritance and interface in oops with java .pptxinheritance and interface in oops with java .pptx
inheritance and interface in oops with java .pptx
janetvidyaanancys
 
java: basics, user input, data type, constructor
java:  basics, user input, data type, constructorjava:  basics, user input, data type, constructor
java: basics, user input, data type, constructor
Shivam Singhal
 
Advanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAdvanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sir
AVINASH KUMAR
 
java tutorial 3
 java tutorial 3 java tutorial 3
java tutorial 3
Tushar Desarda
 
Oops concept
Oops conceptOops concept
Oops concept
baabtra.com - No. 1 supplier of quality freshers
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
backdoor
 
Adv kvr -satya
Adv  kvr -satyaAdv  kvr -satya
Adv kvr -satya
Jyothsna Sree
 
Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satya
Satya Johnny
 
Inheritance and interface
Inheritance and interfaceInheritance and interface
Inheritance and interface
Shubham Sharma
 
11slide
11slide11slide
11slide
IIUM
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
ilias ahmed
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
VijalJain3
 
Introduction to java programming
Introduction to java programmingIntroduction to java programming
Introduction to java programming
shinyduela
 
oops with java modules i & ii.ppt
oops with java modules i & ii.pptoops with java modules i & ii.ppt
oops with java modules i & ii.ppt
rani marri
 
inheritance, Packages and Interfaces.pptx
inheritance, Packages and Interfaces.pptxinheritance, Packages and Interfaces.pptx
inheritance, Packages and Interfaces.pptx
Vanitha Alagesan
 
Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \Object Orinted Programing(OOP) concepts \
Object Orinted Programing(OOP) concepts \
Pritom Chaki
 
OOP with Java - Part 3
OOP with Java - Part 3OOP with Java - Part 3
OOP with Java - Part 3
RatnaJava
 
Modules 333333333³3444444444444444444.pptx
Modules 333333333³3444444444444444444.pptxModules 333333333³3444444444444444444.pptx
Modules 333333333³3444444444444444444.pptx
radhikacordise
 
inheritance and interface in oops with java .pptx
inheritance and interface in oops with java .pptxinheritance and interface in oops with java .pptx
inheritance and interface in oops with java .pptx
janetvidyaanancys
 
java: basics, user input, data type, constructor
java:  basics, user input, data type, constructorjava:  basics, user input, data type, constructor
java: basics, user input, data type, constructor
Shivam Singhal
 
Advanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sirAdvanced java jee material by KV Rao sir
Advanced java jee material by KV Rao sir
AVINASH KUMAR
 
Object Oriented Programming with Java
Object Oriented Programming with JavaObject Oriented Programming with Java
Object Oriented Programming with Java
backdoor
 
Advance java kvr -satya
Advance java  kvr -satyaAdvance java  kvr -satya
Advance java kvr -satya
Satya Johnny
 
Inheritance and interface
Inheritance and interfaceInheritance and interface
Inheritance and interface
Shubham Sharma
 
11slide
11slide11slide
11slide
IIUM
 
Oop features java presentationshow
Oop features java presentationshowOop features java presentationshow
Oop features java presentationshow
ilias ahmed
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
VijalJain3
 
Ad

More from Purvik Rana (9)

Software Quality Assurance - Software Engineering
Software Quality Assurance - Software EngineeringSoftware Quality Assurance - Software Engineering
Software Quality Assurance - Software Engineering
Purvik Rana
 
Software Designing - Software Engineering
Software Designing - Software EngineeringSoftware Designing - Software Engineering
Software Designing - Software Engineering
Purvik Rana
 
Agile Methodology - Software Engineering
Agile Methodology - Software EngineeringAgile Methodology - Software Engineering
Agile Methodology - Software Engineering
Purvik Rana
 
Software Engineering - Basics
Software Engineering - BasicsSoftware Engineering - Basics
Software Engineering - Basics
Purvik Rana
 
Sql queries - Basics
Sql queries - BasicsSql queries - Basics
Sql queries - Basics
Purvik Rana
 
Android Workshop_1
Android Workshop_1Android Workshop_1
Android Workshop_1
Purvik Rana
 
Andriod_Intro
Andriod_IntroAndriod_Intro
Andriod_Intro
Purvik Rana
 
Apple bonjour
Apple bonjourApple bonjour
Apple bonjour
Purvik Rana
 
File system in iOS
File system in iOSFile system in iOS
File system in iOS
Purvik Rana
 
Software Quality Assurance - Software Engineering
Software Quality Assurance - Software EngineeringSoftware Quality Assurance - Software Engineering
Software Quality Assurance - Software Engineering
Purvik Rana
 
Software Designing - Software Engineering
Software Designing - Software EngineeringSoftware Designing - Software Engineering
Software Designing - Software Engineering
Purvik Rana
 
Agile Methodology - Software Engineering
Agile Methodology - Software EngineeringAgile Methodology - Software Engineering
Agile Methodology - Software Engineering
Purvik Rana
 
Software Engineering - Basics
Software Engineering - BasicsSoftware Engineering - Basics
Software Engineering - Basics
Purvik Rana
 
Sql queries - Basics
Sql queries - BasicsSql queries - Basics
Sql queries - Basics
Purvik Rana
 
Android Workshop_1
Android Workshop_1Android Workshop_1
Android Workshop_1
Purvik Rana
 
File system in iOS
File system in iOSFile system in iOS
File system in iOS
Purvik Rana
 
Ad

Recently uploaded (20)

How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18How to Configure Scheduled Actions in odoo 18
How to Configure Scheduled Actions in odoo 18
Celine George
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
Cultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptxCultivation Practice of Garlic in Nepal.pptx
Cultivation Practice of Garlic in Nepal.pptx
UmeshTimilsina1
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
*"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"**"Sensing the World: Insect Sensory Systems"*
*"Sensing the World: Insect Sensory Systems"*
Arshad Shaikh
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...Transform tomorrow: Master benefits analysis with Gen AI today webinar,  30 A...
Transform tomorrow: Master benefits analysis with Gen AI today webinar, 30 A...
Association for Project Management
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 

OOPs Concepts - Android Programming

  • 1. OOPs CONCEPTS FORANDROIDPROGRAMMING OBJECT ORIENTED PROGRAMMING system Purvik Rana
  • 2. intro  A programming paradigm where everything is represented as • an object.  A methodology to design a program using • Classes and Objects .  Simplifies the software development process & maintenance by rich concepts like • Object • Polymorphism • Class • Abstraction • Inheritance • Encapsulation
  • 3. Intro- continue  Object • Entity that has State (Property) and Behaviours (Methods). • For Example: Person, Car, House, Chair.  Class • Collection of Objects ( a logical entity ).  Inheritance • When one object acquires all the properties & behaviours of parent object  provides code Reusability.  Polymorphism • Where one task perform in different ways (overloading & overriding).
  • 4. Intro- continue  Abstraction • Hiding internal details and display only functionality. • It is achieved through Abstract class & Interface.  Encapsulation • Binding Code and Data together into a single unit. • A Java Class is an example of it where all the data members and methods are private to it.
  • 5. NamingConventions Name Convention class name should start with uppercase letter and be a noun e.g. String, Color, Button, System, Thread etc. interface name should start with uppercase letter and be an adjective e.g. Runnable, Remote, ActionListener etc. method name should start with lowercase letter and be a verb e.g. actionPerformed(), main(), print(), println() etc. variable name should start with lowercase letter e.g. firstName, orderNumber etc. package name should be in lowercase letter e.g. java, lang, sql, util etc. constants name should be in uppercase letter. e.g. RED, YELLOW, MAX_PRIORITY etc. CamelCase : If name is combined with two words, second word will start with uppercase letter always
  • 6. ClassDeclaration class Student1{ int id; // data member (also instance variable) String name; // data member(also instance variable) public static void main(String args[]){ Student1 s1 = new Student1(); // creating an object of Student System.out.println(s1.id); // accessing class data member System.out.println(s1.name); } }
  • 7. MethodOverloading  What • Class has method with same name but with different parameters. • Increase readability of the program.  Two ways to perform: • Either change the number of arguments. • Change the data type of arguments. • Not possible by changing the return type of method.
  • 8. Methodoverloading - Example Example-1 Different No of Parameters class Calculation{ void sum(int a,int b) {System.out.println(a+b);} void sum(int a,int b,int c) {System.out.println(a+b+c);} public static void main(String args[]){ Calculation obj=new Calculation(); obj.sum(10,10,10); obj.sum(20,20); } } Example -2 Changing Data type class Calculation2{ void sum(int a,int b) {System.out.println(a+b);} void sum(double a,double b) {System.out.println(a+b);} public static void main(String args[]){ Calculation2 obj=new Calculation2(); obj.sum(10.5,10.5); obj.sum(20,20); } }
  • 9. Constructor  What • Special type of method used to initialize the object. • Invoked at the time of object creation.  Rules • Name must be same as its class name. • Must have no explicit return type.  Type • Default Constructor. • Parameterized Constructor.  Constructor Overloading • Same as method overloading
  • 10. Constructor - example class Student5{ int id; String name; int age; Student5() { } // default Student5(int i,String n){ id = i; name = n; } Student5(int i,String n,int a){ id = i; name = n; age=a; } void display(){ System.out.println(id+" "+name+" "+age);} public static void main(String args[]){ Student5 s1 = new Student5(111,"Karan"); Student5 s2 = new Student5(222,"Aryan",25); s1.display(); s2.display(); } }
  • 11. Inheritance  What • One object acquires all the properties & behaviours of parent object. • Reuse parameters and method of parent class. • Holds IS-A relationship.  Why • Method Overriding (For run time polymorphism) • Code reusability class Subclass-name extends Superclass-name { //methods and fields }
  • 12. Inheritance - continue  Types • Multiple inheritance not supported in Java through Classes • Supported through “Interfaces”
  • 13. Inheritance- example class Employee{ float salary=40000; } class Programmer extends Employee{ int bonus=10000; 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); } }
  • 14. Aggregation  When class has an entity reference  called Aggregation.  Why  for code reusability. class Employee{ int id; String name; Address address; //Address is nothing but some other class ... }  Relationship is : Employee HAS-A address.  Used when there is no IS-A relationship.
  • 15. MethodOverriding  When subclass override same method as declared in Super Class.  Usage • Subclass provides specific implementation of method that it overrides. • Used for runtime polymorphism.  Rules • Method must have same name as the parent class • Must have same parameter as the parent class • Must be a IS-A relationship
  • 16. Methodoverriding- Example Example class Bank{ int getRateOfInterest(){return 0;} } class SBI extends Bank{ int getRateOfInterest(){return 8;} } class ICICI extends Bank{ int getRateOfInterest(){return 7;} }
  • 17. AbstractClass  What • Class declared with Abstract keyword. • Can have abstract & non-abstract methods.  Abstraction • Used to hide implementation details from the user. • Focus on “what it does” not reveal “how it does”.  Two ways to achieve, thorough • Abstract Class • Interface
  • 18. Abstractclass - CONTINUE Example abstract class Bike{ abstract void run(); } class Honda4 extends Bike{ void run(){System.out.println("running safely..");} public static void main(String args[]){ Bike obj = new Honda4(); obj.run(); } }
  • 19. Interface  What • Is a blueprint of a class and abstract methods only. • Should have only abstract methods in Java interface. • Parameters are public, static & final. • Methods are public & abstract.  Why • To achieve full abstraction. • To support multiple inheritance. • To achieve loose coupling.
  • 20. Interface-example-1 Understand Relationship Example: interface printable{ void print(); } class A6 implements printable{ public void print() {System.out.println("Hello");} public static void main(String args[]){ A6 obj = new A6(); obj.print(); } }
  • 21. Interface-example-2 interface Printable{ void print(); } interface Showable{ void show(); } class A7 implements Printable,Showable{ public void print(){System.out.println("Hello");} public void show(){System.out.println("Welcome");} public static void main(String args[]){ A7 obj = new A7(); obj.print(); obj.show(); } }
  • 22. encapsulation  Wrapping code & data together. into a single unit  Fully encapsulated class contain • All data member as private. • Use setter & getter method to set and get the data values.  Advantages • Make class read only or write only • Provides control over the data
  • 23. Encapsulation- example //save as Student.java public class Student{ private String name; public String getName(){ return name; } public void setName(String name){ this.name=name } } //save as Test.java class Test{ public static void main(String[] args){ Student s=new Student(); s.setname("vijay"); System.out.println(s.getName()); } }
  • 24. superkeyword  Is a reference variable used to refer immediate parent class object  Usage • To refer immediate parent class instance variable. • To invoke immediate parent class constructor. • To invoke immediate parent class method.
  • 25. Superkeyword- example Example - 1 class Vehicle{ int speed = 50; } class Bike4 extends Vehicle{ int speed = 100; void display(){ System.out.println(super.speed); //will print speed of Vehicle now } public static void main(String args[]){ Bike4 b = new Bike4(); b.display(); } } Example - 2 class Vehicle{ Vehicle() {System.out.println("Vehicle is created");} } class Bike5 extends Vehicle{ Bike5(){ super(); //will invoke parent class constructor System.out.println("Bike is created"); } public static void main(String args[]){ Bike5 b = new Bike5(); } } Example – 3 class Person{ void message() {System.out.println("welcome");} } class Student16 extends Person{ void message() {System.out.println("welcome to java");} void display(){ message(); //will invoke current class message() method super.message(); //will invoke parent class message() method } public static void main(String args[]){ Student16 s=new Student16(); s.display(); } }
  • 26. Thiskeyword  Is a reference variable used to refer current objects  Usage • to refer current class instance variable • to invoke current class constructor • can be passed as an argument in the method call • can be passed as argument in the constructor call • can also be used to return the current class instance
  • 27. Thiskeyword - example Example - 1 class Student11{ int id; String name; Student11(int id,String name){ this.id = id; this.name = name; } void display() { System.out.println(id+" "+name);} public static void main(String args[]){ Student11 s1 = new Student11(111,"Karan"); Student11 s2 = new Student11(222,"Aryan"); s1.display(); s2.display(); } } Example – 2 class Student13{ int id; String name; Student13() {System.out.println("defaultconstructor is invoked");} Student13(int id,String name){ this (); //it is used to invoked current class constructor. this.id = id; this.name = name; } void display(){System.out.println(id+" "+name);} public static void main(String args[]){ Student13 e1 = new Student13(111,"karan"); Student13 e2 = new Student13(222,"Aryan"); e1.display(); e2.display(); } }
  • 28. THIS IS WHATALLWE’VE LEARN • OBJECT & CLASS • INHERITANCE • ABSTRACTION • ENCAPSULATION • POLYMORPHISM • Super & This Keyword
  翻译: