SlideShare a Scribd company logo
Java/J2EE Programming Training
OOPs Orientation
Page 1Classification: Restricted
Agenda
โ€ข Object Orientation
โ€ข Overloading
โ€ข Overriding
โ€ข Constructor
Page 2Classification: Restricted
Objectives
โ€ข State the benefits of encapsulation in object oriented design and write
code that implements tightly encapsulated classes and the relationships
"is a" and "has a".
โ€ข Write code to invoke overridden or overloaded methods and parental or
overloaded constructors; and describe the effect of invoking these
methods.
โ€ข Write code to construct instances of any concrete class including normal
top level classes and nested classes.
Page 3Classification: Restricted
Encapsulation
โ€ข Hiding the implementation details of a class behind a public
programming interface is called encapsulation
โ€ข Advantage :- Ease of code maintenance and extensibility. You can change
the implementation without causing changes in the calling code
โ€ข Keep the instance variables private(or protected if need be) and allow
access only through public methods
Eg:
public class Employee {
private float salary;
public float getSalary() { return salary; }
public void setSalary(float salary)
{ this.salary=salary; } }
Page 4Classification: Restricted
IS-A Relationship
โ€ข The IS-A relationship stands for inheritance. In Java it is implemented
using the keyword โ€˜extendsโ€™
Eg:
public class Person { // general code for Person here}
public class Employee extends Person
{ // Employee specific code. Person details are inherited
}
โ€ข Here โ€œEmployee extends Personโ€ means that โ€œEmployee IS-A Personโ€
Page 5Classification: Restricted
HAS-A Relationship
โ€ข If an instance of class A has a reference to an instance of class B, we say
that class A HAS-A B
Eg:
class Manager {
private Secretary s;
}
class Secretary {}
// Here the Manager class can make use of the functionality of the
Secretary class, by delegating work
Page 6Classification: Restricted
Overloading
โ€ข Overloading methods have the same name
โ€ข They must have different argument lists
โ€ข They may have different return types
โ€ข They may have different access modifiers
โ€ข They may throw different exceptions
โ€ข A subclass can overload super class methods
โ€ข Constructors can be overloaded
Page 7Classification: Restricted
Overloading Example
Eg:
class A {
int j;
void test() { }
void test(int i) { j=i; } // Overloaded in same class
}
class B extends A {
int test(String s) // Overloaded in subclass
{ System.out.println(s); }
}
Page 8Classification: Restricted
Overriding
โ€ข The overriding method must have the same name, arguments and return
type as the overridden method
โ€ข The overriding method cannot be less public can the overridden method
โ€ข The overriding method should not throw new or broader checked
exceptions
โ€ข Polymorphism comes into action during overriding, the method invoked
depends on the actual object type at runtime. If the object belongs to
superclass, superclass method is called and if the object belongs to
subclass, the subclass version is invoked
Page 9Classification: Restricted
Overriding Example
Eg:
class A {
void print() { System.out.println(โ€œBaseโ€); }
}
class B extends A{
void print() { System.out.println(โ€œDerivedโ€); }
public static void main(String args[]) {
A obj=new B();
obj.print(); // โ€œDerivedโ€ is printed
}
}
Page 10Classification: Restricted
Polymorphism and Overloading
โ€ข Polymorphism comes into play in overriding, but not in overloading
methods
Eg:
class A {
void print() { System.out.println(โ€œBaseโ€); }
}
class B extends A{
void print(String s) { System.out.println(โ€œDerivedโ€); }
public static void main(String args[]) {
A obj=new B();
obj.print(โ€œhelloโ€); // Wonโ€™t compile
}
}
Page 11Classification: Restricted
Difference Between Overloaded and Overridden Methods
Overloaded Method Overridden Method
Argument list Must change Must not change
Return type Can change Must not change
Exceptions Can change Can reduce or eliminate. Must
not throw new or broader
checked exceptions.
Access Can change Must not make more restrictive
(can be less restrictive)
Invocation Reference type determines which overloaded version
(based on declared argument types) is selected.
Happens at compile time. The actual method thatโ€™s
invoked is still a virtual method invocation that
happens at runtime, but the compiler will already
know the signature of the method to be invoked. So
at runtime, the argument match will already have
been nailed down, just not the actual class in which
the method lives.
Object type (in other words, the
type of the actual instance on the
heap) determines which method
is selected. Happens at runtime.
Page 12Classification: Restricted
Constructor Overloading Example
Eg:
class Base {
Base() {}
Base(int a)
{ System.out.println(a); } //Overloaded constructors
}
class Derived {
Derived(int a, int b){ super(a); }
}
Page 13Classification: Restricted
Extra points to remember..
โ€ข Final methods cannot be overridden
โ€ข The overloading method which will be used is decided at compile time,
looking at the reference type
โ€ข Constructors can be overloaded, but not overridden
โ€ข Overridden methods can throw any unchecked exceptions, or narrower
checked exceptions
โ€ข Methods with the modifier โ€˜finalโ€™ cannot be overridden
โ€ข If a method cannot be inherited, it cannot be overridden
โ€ข To invoke the superclass version of an overridden method from the
subclass, use super.method();
Page 14Classification: Restricted
Objective
โ€ข For a given class, determine if a default constructor will be created, and if
so, state the prototype of that constructor.
Page 15Classification: Restricted
Constructors
โ€ข A constructor is called whenever an object is instantiated
โ€ข The constructor name must match the name of the class
โ€ข Constructors must not have a return type
โ€ข Constructors can have any access modifier, even private
โ€ข Constructors can be overloaded, but not inherited
Page 16Classification: Restricted
Invoking Constructors
โ€ข To invoke a constructor in the same class, invoke this() with matching
arguments
โ€ข To invoke a constructor in the super class, invoke super() with matching
arguments
โ€ข A constructor can be invoked only from another constructor
โ€ข When a subclass object is created all the super class constructors are
invoked in order starting from the top of the hierarchy
Page 17Classification: Restricted
Default Constructors
โ€ข A default constructor is created by the compiler only if you have not
written any other constructors in the class
โ€ข The default constructor has no arguments
โ€ข The default constructor calls the no argument constructor of the super
class
โ€ข The default constructor has the same access modifier as the class
Page 18Classification: Restricted
Compiler-Generated Constructor Code
Class Code (what you type) Compiler-Generated Constructor Code
(In Bold Type)
class Foo { } class Foo {
Foo() { super(); } }
class Foo { Foo() { } } class Foo { Foo() { super(); } }
public class Foo { } class Foo { public Foo() { super(); } }
class Foo { Foo(String s) { } } class Foo { Foo(String s) { super(); } }
class Foo { Foo(String s) { super(); } } Nothing-compiler doesnโ€™t need to insert
anything
class Foo { void Foo() { } } class Foo { void Foo() { }
Foo(){ super(); } }
Page 19Classification: Restricted
Extra points to rememberโ€ฆ
โ€ข A call to this() or super() can be made only from a constructor and it
should be the first statement in it
โ€ข You can either call this() or super(), not both, from the same constructor
โ€ข Subclasses without any declared constructors will not compile if the
super class doesnโ€™t have a default constructor
โ€ข A method with the same name as the class is not a constructor if it has a
return type, but it is a normal method
โ€ข Abstract classes have constructors, but interfaces donโ€™t
Page 20Classification: Restricted
Objective
โ€ข Identify legal return types for any method given the declarations of all
related methods in this or parent classes.
Page 21Classification: Restricted
Return Types in Overloading and Overriding
โ€ข Return type of the overriding method should match that of the
overridden method
โ€ข Return types of overloaded methods can be different, but changing only
the return type is not legal. The arguments should also be different
โ€ข A subclass can overload methods in the super class
Ex: class Base {
void callme() {} }
class Derived extends Base {
String callme(int y){return null;}
}
Page 22Classification: Restricted
Primitive Return types
โ€ข In a method with a primitive return type, you can return any value or
variable which can be explicitly cast to the declared return type
Eg:
public int fun1() {
char c=โ€˜Aโ€™;
return c;}
public int fun2() {
float f=100.45f;
return (int)f;
}
Page 23Classification: Restricted
Extra points to rememberโ€ฆ
โ€ข Methods which return object reference types are allowed to return a null
value
โ€ข Casting rules apply when returning values
โ€ข A method that declares a class return type can return any object which is
of the subclass type
โ€ข A method that declares an interface return type can return any object
whose class implements the interface
โ€ข Nothing should be returned from a function which has void return type
Page 24Classification: Restricted
Thank You

More Related Content

What's hot (17)

Packages
PackagesPackages
Packages
Nuha Noor
ย 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritance
teach4uin
ย 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Nuha Noor
ย 
โ€ซChapter3 inheritance
โ€ซChapter3 inheritanceโ€ซChapter3 inheritance
โ€ซChapter3 inheritance
Mahmoud Alfarra
ย 
inheritance
inheritanceinheritance
inheritance
Mohit Patodia
ย 
Java
JavaJava
Java
NAIM PARVEZ GALIB
ย 
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
ย 
Dynamic method dispatch
Dynamic method dispatchDynamic method dispatch
Dynamic method dispatch
yugandhar vadlamudi
ย 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
Arjun Shanka
ย 
02 java basics
02 java basics02 java basics
02 java basics
bsnl007
ย 
Inheritance and polymorphism
Inheritance and polymorphism   Inheritance and polymorphism
Inheritance and polymorphism
baabtra.com - No. 1 supplier of quality freshers
ย 
Java session2
Java session2Java session2
Java session2
Rajeev Kumar
ย 
ุงู„ุจุฑู…ุฌุฉ ุงู„ู‡ุฏููŠุฉ ุจู„ุบุฉ ุฌุงูุง - ู…ูุงู‡ูŠู… ุฃุณุงุณูŠุฉ
ุงู„ุจุฑู…ุฌุฉ ุงู„ู‡ุฏููŠุฉ ุจู„ุบุฉ ุฌุงูุง - ู…ูุงู‡ูŠู… ุฃุณุงุณูŠุฉ ุงู„ุจุฑู…ุฌุฉ ุงู„ู‡ุฏููŠุฉ ุจู„ุบุฉ ุฌุงูุง - ู…ูุงู‡ูŠู… ุฃุณุงุณูŠุฉ
ุงู„ุจุฑู…ุฌุฉ ุงู„ู‡ุฏููŠุฉ ุจู„ุบุฉ ุฌุงูุง - ู…ูุงู‡ูŠู… ุฃุณุงุณูŠุฉ
Mahmoud Alfarra
ย 
Session 09 - OOP with Java - Part 3
Session 09 - OOP with Java - Part 3Session 09 - OOP with Java - Part 3
Session 09 - OOP with Java - Part 3
PawanMM
ย 
Review Session - Part -2
Review Session - Part -2Review Session - Part -2
Review Session - Part -2
Hitesh-Java
ย 
Session 08 - OOP with Java - continued
Session 08 - OOP with Java - continuedSession 08 - OOP with Java - continued
Session 08 - OOP with Java - continued
PawanMM
ย 
โ€ซโ€ซChapter4 Polymorphism
โ€ซโ€ซChapter4 Polymorphismโ€ซโ€ซChapter4 Polymorphism
โ€ซโ€ซChapter4 Polymorphism
Mahmoud Alfarra
ย 
Packages
PackagesPackages
Packages
Nuha Noor
ย 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritance
teach4uin
ย 
Polymorphism
PolymorphismPolymorphism
Polymorphism
Nuha Noor
ย 
โ€ซChapter3 inheritance
โ€ซChapter3 inheritanceโ€ซChapter3 inheritance
โ€ซChapter3 inheritance
Mahmoud Alfarra
ย 
inheritance
inheritanceinheritance
inheritance
Mohit Patodia
ย 
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
ย 
Dynamic method dispatch
Dynamic method dispatchDynamic method dispatch
Dynamic method dispatch
yugandhar vadlamudi
ย 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
Arjun Shanka
ย 
02 java basics
02 java basics02 java basics
02 java basics
bsnl007
ย 
Java session2
Java session2Java session2
Java session2
Rajeev Kumar
ย 
ุงู„ุจุฑู…ุฌุฉ ุงู„ู‡ุฏููŠุฉ ุจู„ุบุฉ ุฌุงูุง - ู…ูุงู‡ูŠู… ุฃุณุงุณูŠุฉ
ุงู„ุจุฑู…ุฌุฉ ุงู„ู‡ุฏููŠุฉ ุจู„ุบุฉ ุฌุงูุง - ู…ูุงู‡ูŠู… ุฃุณุงุณูŠุฉ ุงู„ุจุฑู…ุฌุฉ ุงู„ู‡ุฏููŠุฉ ุจู„ุบุฉ ุฌุงูุง - ู…ูุงู‡ูŠู… ุฃุณุงุณูŠุฉ
ุงู„ุจุฑู…ุฌุฉ ุงู„ู‡ุฏููŠุฉ ุจู„ุบุฉ ุฌุงูุง - ู…ูุงู‡ูŠู… ุฃุณุงุณูŠุฉ
Mahmoud Alfarra
ย 
Session 09 - OOP with Java - Part 3
Session 09 - OOP with Java - Part 3Session 09 - OOP with Java - Part 3
Session 09 - OOP with Java - Part 3
PawanMM
ย 
Review Session - Part -2
Review Session - Part -2Review Session - Part -2
Review Session - Part -2
Hitesh-Java
ย 
Session 08 - OOP with Java - continued
Session 08 - OOP with Java - continuedSession 08 - OOP with Java - continued
Session 08 - OOP with Java - continued
PawanMM
ย 
โ€ซโ€ซChapter4 Polymorphism
โ€ซโ€ซChapter4 Polymorphismโ€ซโ€ซChapter4 Polymorphism
โ€ซโ€ซChapter4 Polymorphism
Mahmoud Alfarra
ย 

Similar to Java OOPs (20)

Lecture d-inheritance
Lecture d-inheritanceLecture d-inheritance
Lecture d-inheritance
Tej Kiran
ย 
Java
JavaJava
Java
nirbhayverma8
ย 
Quick Interview Preparation for C# All Concepts
Quick Interview Preparation for C# All ConceptsQuick Interview Preparation for C# All Concepts
Quick Interview Preparation for C# All Concepts
Karmanjay Verma
ย 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
RatnaJava
ย 
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
AshwathGupta
ย 
Ch5 inheritance
Ch5 inheritanceCh5 inheritance
Ch5 inheritance
HarshithaAllu
ย 
Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class features
Rakesh Madugula
ย 
Btech chapter notes batcha ros zir skznzjsbaajz z
Btech chapter notes batcha ros zir skznzjsbaajz zBtech chapter notes batcha ros zir skznzjsbaajz z
Btech chapter notes batcha ros zir skznzjsbaajz z
bhatiaanushka101
ย 
04_-_Inheritance_Polymorphism_and_Interfaces.pdf
04_-_Inheritance_Polymorphism_and_Interfaces.pdf04_-_Inheritance_Polymorphism_and_Interfaces.pdf
04_-_Inheritance_Polymorphism_and_Interfaces.pdf
markbrianBautista
ย 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
Abdii Rashid
ย 
javainheritance
javainheritancejavainheritance
javainheritance
Arjun Shanka
ย 
Unit 4
Unit 4Unit 4
Unit 4
LOVELY PROFESSIONAL UNIVERSITY
ย 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
Hari kiran G
ย 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overriding
NithyaN19
ย 
Unit 7 inheritance
Unit 7 inheritanceUnit 7 inheritance
Unit 7 inheritance
atcnerd
ย 
Inheritance
InheritanceInheritance
Inheritance
abhay singh
ย 
PPT Lecture-1.4.pptx
PPT Lecture-1.4.pptxPPT Lecture-1.4.pptx
PPT Lecture-1.4.pptx
HimanshuPandey957216
ย 
28csharp
28csharp28csharp
28csharp
Sireesh K
ย 
28c
28c28c
28c
Sireesh K
ย 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
GaneshKumarKanthiah
ย 
Lecture d-inheritance
Lecture d-inheritanceLecture d-inheritance
Lecture d-inheritance
Tej Kiran
ย 
Quick Interview Preparation for C# All Concepts
Quick Interview Preparation for C# All ConceptsQuick Interview Preparation for C# All Concepts
Quick Interview Preparation for C# All Concepts
Karmanjay Verma
ย 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
RatnaJava
ย 
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
5. OBJECT ORIENTED PROGRAMMING USING JAVA - INHERITANCE.ppt
AshwathGupta
ย 
Ch5 inheritance
Ch5 inheritanceCh5 inheritance
Ch5 inheritance
HarshithaAllu
ย 
Md06 advance class features
Md06 advance class featuresMd06 advance class features
Md06 advance class features
Rakesh Madugula
ย 
Btech chapter notes batcha ros zir skznzjsbaajz z
Btech chapter notes batcha ros zir skznzjsbaajz zBtech chapter notes batcha ros zir skznzjsbaajz z
Btech chapter notes batcha ros zir skznzjsbaajz z
bhatiaanushka101
ย 
04_-_Inheritance_Polymorphism_and_Interfaces.pdf
04_-_Inheritance_Polymorphism_and_Interfaces.pdf04_-_Inheritance_Polymorphism_and_Interfaces.pdf
04_-_Inheritance_Polymorphism_and_Interfaces.pdf
markbrianBautista
ย 
Java chapter 5
Java chapter 5Java chapter 5
Java chapter 5
Abdii Rashid
ย 
javainheritance
javainheritancejavainheritance
javainheritance
Arjun Shanka
ย 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
Hari kiran G
ย 
Java Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overridingJava Inheritance - sub class constructors - Method overriding
Java Inheritance - sub class constructors - Method overriding
NithyaN19
ย 
Unit 7 inheritance
Unit 7 inheritanceUnit 7 inheritance
Unit 7 inheritance
atcnerd
ย 
Inheritance
InheritanceInheritance
Inheritance
abhay singh
ย 
28csharp
28csharp28csharp
28csharp
Sireesh K
ย 
28c
28c28c
28c
Sireesh K
ย 
Ad

More from DeeptiJava (13)

Generating the Server Response: HTTP Status Codes
Generating the Server Response: HTTP Status CodesGenerating the Server Response: HTTP Status Codes
Generating the Server Response: HTTP Status Codes
DeeptiJava
ย 
Java Generics
Java GenericsJava Generics
Java Generics
DeeptiJava
ย 
Java Collection
Java CollectionJava Collection
Java Collection
DeeptiJava
ย 
Java Exception Handling
Java Exception HandlingJava Exception Handling
Java Exception Handling
DeeptiJava
ย 
Java Access Specifier
Java Access SpecifierJava Access Specifier
Java Access Specifier
DeeptiJava
ย 
Java JDBC
Java JDBCJava JDBC
Java JDBC
DeeptiJava
ย 
Java Thread
Java ThreadJava Thread
Java Thread
DeeptiJava
ย 
Java Inner Class
Java Inner ClassJava Inner Class
Java Inner Class
DeeptiJava
ย 
JSP Part 2
JSP Part 2JSP Part 2
JSP Part 2
DeeptiJava
ย 
JSP Part 1
JSP Part 1JSP Part 1
JSP Part 1
DeeptiJava
ย 
Java I/O
Java I/OJava I/O
Java I/O
DeeptiJava
ย 
Java Hibernate Basics
Java Hibernate BasicsJava Hibernate Basics
Java Hibernate Basics
DeeptiJava
ย 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
DeeptiJava
ย 
Generating the Server Response: HTTP Status Codes
Generating the Server Response: HTTP Status CodesGenerating the Server Response: HTTP Status Codes
Generating the Server Response: HTTP Status Codes
DeeptiJava
ย 
Java Generics
Java GenericsJava Generics
Java Generics
DeeptiJava
ย 
Java Collection
Java CollectionJava Collection
Java Collection
DeeptiJava
ย 
Java Exception Handling
Java Exception HandlingJava Exception Handling
Java Exception Handling
DeeptiJava
ย 
Java Access Specifier
Java Access SpecifierJava Access Specifier
Java Access Specifier
DeeptiJava
ย 
Java JDBC
Java JDBCJava JDBC
Java JDBC
DeeptiJava
ย 
Java Thread
Java ThreadJava Thread
Java Thread
DeeptiJava
ย 
Java Inner Class
Java Inner ClassJava Inner Class
Java Inner Class
DeeptiJava
ย 
JSP Part 2
JSP Part 2JSP Part 2
JSP Part 2
DeeptiJava
ย 
JSP Part 1
JSP Part 1JSP Part 1
JSP Part 1
DeeptiJava
ย 
Java I/O
Java I/OJava I/O
Java I/O
DeeptiJava
ย 
Java Hibernate Basics
Java Hibernate BasicsJava Hibernate Basics
Java Hibernate Basics
DeeptiJava
ย 
Introduction to Java
Introduction to JavaIntroduction to Java
Introduction to Java
DeeptiJava
ย 
Ad

Recently uploaded (20)

Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
ย 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
ย 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
ย 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
ย 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
ย 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
ย 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
ย 
โ€œState-space Models vs. Transformers for Ultra-low-power Edge AI,โ€ a Presenta...
โ€œState-space Models vs. Transformers for Ultra-low-power Edge AI,โ€ a Presenta...โ€œState-space Models vs. Transformers for Ultra-low-power Edge AI,โ€ a Presenta...
โ€œState-space Models vs. Transformers for Ultra-low-power Edge AI,โ€ a Presenta...
Edge AI and Vision Alliance
ย 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry ReportThe State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
ย 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
ย 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
ย 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
ย 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
ย 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
ย 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
ย 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
ย 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
ย 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
ย 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
ย 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
ย 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementaryMurdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
ย 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free DownloadViral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
ย 
Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.Introduction to Internet of things .ppt.
Introduction to Internet of things .ppt.
hok12341073
ย 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven InfrastructureNo-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
ย 
Trends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary MeekerTrends Artificial Intelligence - Mary Meeker
Trends Artificial Intelligence - Mary Meeker
Clive Dickens
ย 
TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025TimeSeries Machine Learning - PyData London 2025
TimeSeries Machine Learning - PyData London 2025
Suyash Joshi
ย 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
ย 
โ€œState-space Models vs. Transformers for Ultra-low-power Edge AI,โ€ a Presenta...
โ€œState-space Models vs. Transformers for Ultra-low-power Edge AI,โ€ a Presenta...โ€œState-space Models vs. Transformers for Ultra-low-power Edge AI,โ€ a Presenta...
โ€œState-space Models vs. Transformers for Ultra-low-power Edge AI,โ€ a Presenta...
Edge AI and Vision Alliance
ย 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry ReportThe State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
ย 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdfEdge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
ย 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy SurveyTrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
ย 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data ResilienceFloods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
ย 
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and ImplementationAI Agents in Logistics and Supply Chain Applications Benefits and Implementation
AI Agents in Logistics and Supply Chain Applications Benefits and Implementation
Christine Shepherd
ย 
Crypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdfCrypto Super 500 - 14th Report - June2025.pdf
Crypto Super 500 - 14th Report - June2025.pdf
Stephen Perrenod
ย 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent IntegrationPyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
ย 
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdfHow Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
How Advanced Environmental Detection Is Revolutionizing Oil & Gas Safety.pdf
Rejig Digital
ย 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
ย 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdfvertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
ย 
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdfBoosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Boosting MySQL with Vector Search -THE VECTOR SEARCH CONFERENCE 2025 .pdf
Alkin Tezuysal
ย 
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Creating an Accessible Future-How AI-powered Accessibility Testing is Shaping...
Impelsys Inc.
ย 

Java OOPs

  • 2. Page 1Classification: Restricted Agenda โ€ข Object Orientation โ€ข Overloading โ€ข Overriding โ€ข Constructor
  • 3. Page 2Classification: Restricted Objectives โ€ข State the benefits of encapsulation in object oriented design and write code that implements tightly encapsulated classes and the relationships "is a" and "has a". โ€ข Write code to invoke overridden or overloaded methods and parental or overloaded constructors; and describe the effect of invoking these methods. โ€ข Write code to construct instances of any concrete class including normal top level classes and nested classes.
  • 4. Page 3Classification: Restricted Encapsulation โ€ข Hiding the implementation details of a class behind a public programming interface is called encapsulation โ€ข Advantage :- Ease of code maintenance and extensibility. You can change the implementation without causing changes in the calling code โ€ข Keep the instance variables private(or protected if need be) and allow access only through public methods Eg: public class Employee { private float salary; public float getSalary() { return salary; } public void setSalary(float salary) { this.salary=salary; } }
  • 5. Page 4Classification: Restricted IS-A Relationship โ€ข The IS-A relationship stands for inheritance. In Java it is implemented using the keyword โ€˜extendsโ€™ Eg: public class Person { // general code for Person here} public class Employee extends Person { // Employee specific code. Person details are inherited } โ€ข Here โ€œEmployee extends Personโ€ means that โ€œEmployee IS-A Personโ€
  • 6. Page 5Classification: Restricted HAS-A Relationship โ€ข If an instance of class A has a reference to an instance of class B, we say that class A HAS-A B Eg: class Manager { private Secretary s; } class Secretary {} // Here the Manager class can make use of the functionality of the Secretary class, by delegating work
  • 7. Page 6Classification: Restricted Overloading โ€ข Overloading methods have the same name โ€ข They must have different argument lists โ€ข They may have different return types โ€ข They may have different access modifiers โ€ข They may throw different exceptions โ€ข A subclass can overload super class methods โ€ข Constructors can be overloaded
  • 8. Page 7Classification: Restricted Overloading Example Eg: class A { int j; void test() { } void test(int i) { j=i; } // Overloaded in same class } class B extends A { int test(String s) // Overloaded in subclass { System.out.println(s); } }
  • 9. Page 8Classification: Restricted Overriding โ€ข The overriding method must have the same name, arguments and return type as the overridden method โ€ข The overriding method cannot be less public can the overridden method โ€ข The overriding method should not throw new or broader checked exceptions โ€ข Polymorphism comes into action during overriding, the method invoked depends on the actual object type at runtime. If the object belongs to superclass, superclass method is called and if the object belongs to subclass, the subclass version is invoked
  • 10. Page 9Classification: Restricted Overriding Example Eg: class A { void print() { System.out.println(โ€œBaseโ€); } } class B extends A{ void print() { System.out.println(โ€œDerivedโ€); } public static void main(String args[]) { A obj=new B(); obj.print(); // โ€œDerivedโ€ is printed } }
  • 11. Page 10Classification: Restricted Polymorphism and Overloading โ€ข Polymorphism comes into play in overriding, but not in overloading methods Eg: class A { void print() { System.out.println(โ€œBaseโ€); } } class B extends A{ void print(String s) { System.out.println(โ€œDerivedโ€); } public static void main(String args[]) { A obj=new B(); obj.print(โ€œhelloโ€); // Wonโ€™t compile } }
  • 12. Page 11Classification: Restricted Difference Between Overloaded and Overridden Methods Overloaded Method Overridden Method Argument list Must change Must not change Return type Can change Must not change Exceptions Can change Can reduce or eliminate. Must not throw new or broader checked exceptions. Access Can change Must not make more restrictive (can be less restrictive) Invocation Reference type determines which overloaded version (based on declared argument types) is selected. Happens at compile time. The actual method thatโ€™s invoked is still a virtual method invocation that happens at runtime, but the compiler will already know the signature of the method to be invoked. So at runtime, the argument match will already have been nailed down, just not the actual class in which the method lives. Object type (in other words, the type of the actual instance on the heap) determines which method is selected. Happens at runtime.
  • 13. Page 12Classification: Restricted Constructor Overloading Example Eg: class Base { Base() {} Base(int a) { System.out.println(a); } //Overloaded constructors } class Derived { Derived(int a, int b){ super(a); } }
  • 14. Page 13Classification: Restricted Extra points to remember.. โ€ข Final methods cannot be overridden โ€ข The overloading method which will be used is decided at compile time, looking at the reference type โ€ข Constructors can be overloaded, but not overridden โ€ข Overridden methods can throw any unchecked exceptions, or narrower checked exceptions โ€ข Methods with the modifier โ€˜finalโ€™ cannot be overridden โ€ข If a method cannot be inherited, it cannot be overridden โ€ข To invoke the superclass version of an overridden method from the subclass, use super.method();
  • 15. Page 14Classification: Restricted Objective โ€ข For a given class, determine if a default constructor will be created, and if so, state the prototype of that constructor.
  • 16. Page 15Classification: Restricted Constructors โ€ข A constructor is called whenever an object is instantiated โ€ข The constructor name must match the name of the class โ€ข Constructors must not have a return type โ€ข Constructors can have any access modifier, even private โ€ข Constructors can be overloaded, but not inherited
  • 17. Page 16Classification: Restricted Invoking Constructors โ€ข To invoke a constructor in the same class, invoke this() with matching arguments โ€ข To invoke a constructor in the super class, invoke super() with matching arguments โ€ข A constructor can be invoked only from another constructor โ€ข When a subclass object is created all the super class constructors are invoked in order starting from the top of the hierarchy
  • 18. Page 17Classification: Restricted Default Constructors โ€ข A default constructor is created by the compiler only if you have not written any other constructors in the class โ€ข The default constructor has no arguments โ€ข The default constructor calls the no argument constructor of the super class โ€ข The default constructor has the same access modifier as the class
  • 19. Page 18Classification: Restricted Compiler-Generated Constructor Code Class Code (what you type) Compiler-Generated Constructor Code (In Bold Type) class Foo { } class Foo { Foo() { super(); } } class Foo { Foo() { } } class Foo { Foo() { super(); } } public class Foo { } class Foo { public Foo() { super(); } } class Foo { Foo(String s) { } } class Foo { Foo(String s) { super(); } } class Foo { Foo(String s) { super(); } } Nothing-compiler doesnโ€™t need to insert anything class Foo { void Foo() { } } class Foo { void Foo() { } Foo(){ super(); } }
  • 20. Page 19Classification: Restricted Extra points to rememberโ€ฆ โ€ข A call to this() or super() can be made only from a constructor and it should be the first statement in it โ€ข You can either call this() or super(), not both, from the same constructor โ€ข Subclasses without any declared constructors will not compile if the super class doesnโ€™t have a default constructor โ€ข A method with the same name as the class is not a constructor if it has a return type, but it is a normal method โ€ข Abstract classes have constructors, but interfaces donโ€™t
  • 21. Page 20Classification: Restricted Objective โ€ข Identify legal return types for any method given the declarations of all related methods in this or parent classes.
  • 22. Page 21Classification: Restricted Return Types in Overloading and Overriding โ€ข Return type of the overriding method should match that of the overridden method โ€ข Return types of overloaded methods can be different, but changing only the return type is not legal. The arguments should also be different โ€ข A subclass can overload methods in the super class Ex: class Base { void callme() {} } class Derived extends Base { String callme(int y){return null;} }
  • 23. Page 22Classification: Restricted Primitive Return types โ€ข In a method with a primitive return type, you can return any value or variable which can be explicitly cast to the declared return type Eg: public int fun1() { char c=โ€˜Aโ€™; return c;} public int fun2() { float f=100.45f; return (int)f; }
  • 24. Page 23Classification: Restricted Extra points to rememberโ€ฆ โ€ข Methods which return object reference types are allowed to return a null value โ€ข Casting rules apply when returning values โ€ข A method that declares a class return type can return any object which is of the subclass type โ€ข A method that declares an interface return type can return any object whose class implements the interface โ€ข Nothing should be returned from a function which has void return type