SlideShare a Scribd company logo
2
Most read
3
Most read
6
Most read
Dynamic Method Dispatch
Abstract Class
Using Final with inheritance
Dynamic method dispatch
• Dynamic method dispatch is one type of mechanism by which a call to an
overridden method is resolved at run time
• When an overridden method is called through the object of superclass
then Java determines which version of that method to execute, based
upon the type of the object being referred to at the time the call occurs,
hence determination is made at run time.
• Go through the example below
• /* * Dynamic Method Dispach */
class Class_A
{ void demo()
{ System.out.println("the class A method called"); }
}
class Class_B extends Class_A
{ void demo()
{ System.out.println("the class B method called"); }
}
public class inheritance
{ public static void main(String[] y)
{ Class_A a=new Class_A();
a.demo();
/*
* The below one is called upcasting
*/
Class_A b=new Class_B();
b.demo();
a=b;
a.demo();
}
}
Difference between Static binding and Dynamic
binding in java ?
• Static binding in Java occurs during compile time
• dynamic binding occurs during runtime.
• Overloaded methods are bonded using static binding
• overridden methods are bonded using dynamic binding at runtime.
Abstract classes
• If a class contain any abstract method then the class is declared as
abstract class.
• An abstract class is never instantiated.
• Although it does not provide 100% abstraction because it can also have
concrete method.
Syntax
• Abstract class <class_name>{}
Abstract method
• Method that are declared without any body within an abstract class is
known as abstract method.
• The method body will be defined by its subclass
Syntax
Abstract return_type method_name(arguments list);
/* * abstract class and method */
abstract class Demo_A
{ abstract void Demo();//abstract method }
class Demo_B extends Demo_A
{ void Demo()
{ System.out.println("hello"); }
}
public class Abstract_Demo
{ public static void main(String[] y)
{ Demo_B b=new Demo_B();
b.Demo();
}
}
Abstract class with Concrete methods
/* * abstract class and Concrete method */
abstract class Demo_A
{ abstract void Demo(); //abstract method
void demo_a() //concrete method
{ System.out.println("the method of abstract class concrete method"); }
}
class Demo_B extends Demo_A
{ void Demo()
{ System.out.println("hello"); }
}
public class Abstract_Demo
{ public static void main(String[] y)
{ Demo_B b=new Demo_B();
b.Demo();
b.demo_a();
//Demo_A a=new Demo_A();
//a.demo_a();
/* * try to remove the above comments to under the concept */
/* * we can create refference variable for abstract classes */
Demo_A a=new Demo_B();
a.Demo();
}
}
Final method
• A final method cannot be overridden
• Which means even though a sub class can call the final method of parent class without
any issues but it cannot override it
class Super
{ final void demo()
{ System.out.println("hello"); }
}
class Sub_ extends Super
{ /*void demo()
{
System.out.println("hello world");
}*/
void demo_1()
{ System.out.println("hello world"); }
}
class Demo
{ public static void main(String[] y)
{ Sub_ s=new Sub_();
s.demo();
}
}
Final class
• We cannot extend a final class prevent inheritance
final class Super
{ void demo()
{ System.out.println("hello"); }
}
class Sub_ extends Super
{ void demo_1()
{ System.out.println("hello world"); }
}
class Demo
{ public static void main(String[] y)
{ Sub_ s=new Sub_(); }
}

More Related Content

PPTX
Computer system bus
PPTX
Inheritance in java
PPTX
java interface and packages
PPTX
Asymptotic notations
PPTX
Need for Software Engineering
PPT
Css Ppt
Computer system bus
Inheritance in java
java interface and packages
Asymptotic notations
Need for Software Engineering
Css Ppt

What's hot (20)

PPT
Abstract class in java
PDF
Arrays in Java
PPTX
Structure of java program diff c- cpp and java
PPSX
Modules and packages in python
PPTX
Java packages
PPTX
Polymorphism in java
PPT
Thread model in java
PPTX
Java Method, Static Block
PPT
Final keyword in java
PPTX
Method overloading
PPTX
This keyword in java
PPTX
Classes objects in java
PPTX
Data types in java
PPTX
Java program structure
PPTX
Python-DataAbstarction.pptx
PPTX
Java abstract class & abstract methods
ODP
Multithreading In Java
PPTX
PDF
Java threads
PDF
Strings in java
Abstract class in java
Arrays in Java
Structure of java program diff c- cpp and java
Modules and packages in python
Java packages
Polymorphism in java
Thread model in java
Java Method, Static Block
Final keyword in java
Method overloading
This keyword in java
Classes objects in java
Data types in java
Java program structure
Python-DataAbstarction.pptx
Java abstract class & abstract methods
Multithreading In Java
Java threads
Strings in java
Ad

Viewers also liked (20)

PPTX
Ppt on this and super keyword
PPT
Runnable interface.34
PPT
Exception handling
PPT
Java exception
PPT
Access Protection
PPTX
Effective Java - Chapter 4: Classes and Interfaces
PPTX
Exceptions in Java
PPTX
Exception handling in asp.net
PPT
Exception Handling Java
ODP
Toolbarexample
PPT
02basics
DOC
Non ieee dot net projects list
PDF
Yaazli International Spring Training
PDF
Java quick reference v2
DOCX
Java Exception handling
PDF
Yaazli International Web Project Workshop
PPTX
For Loops and Variables in Java
PPTX
Exception handling in java
PDF
Yaazli International AngularJS 5 Training
PDF
Yaazli International Hibernate Training
Ppt on this and super keyword
Runnable interface.34
Exception handling
Java exception
Access Protection
Effective Java - Chapter 4: Classes and Interfaces
Exceptions in Java
Exception handling in asp.net
Exception Handling Java
Toolbarexample
02basics
Non ieee dot net projects list
Yaazli International Spring Training
Java quick reference v2
Java Exception handling
Yaazli International Web Project Workshop
For Loops and Variables in Java
Exception handling in java
Yaazli International AngularJS 5 Training
Yaazli International Hibernate Training
Ad

Similar to Dynamic method dispatch (20)

PPT
Java inheritance
PPTX
Inheritance
PPTX
FINAL_DAY9_METHOD_OVERRIDING_Role and benefits .pptx
PPT
Best Core Java Training In Bangalore
PPT
Inheritance
PPTX
Abstract Class & Abstract Method in Core Java
PPT
Object Oriented Programming with Java
PPTX
Object Oriented Programming Inheritance with case study
PPTX
Inheritance.pptx
PPTX
Class introduction in java
DOCX
JAVA Notes - All major concepts covered with examples
PPTX
OBJECT ORIENTED PROGRAMMING STRUCU2.pptx
DOCX
Unit-3 Practice Programs-5.docx
PPTX
Inheritance
DOCX
Keyword of java
PPS
Inheritance chepter 7
DOCX
Binding,interface,abstarct class
PPTX
Unit3 inheritance
PPTX
Polymorphism presentation in java
PDF
polymorphismpresentation-160825122725.pdf
Java inheritance
Inheritance
FINAL_DAY9_METHOD_OVERRIDING_Role and benefits .pptx
Best Core Java Training In Bangalore
Inheritance
Abstract Class & Abstract Method in Core Java
Object Oriented Programming with Java
Object Oriented Programming Inheritance with case study
Inheritance.pptx
Class introduction in java
JAVA Notes - All major concepts covered with examples
OBJECT ORIENTED PROGRAMMING STRUCU2.pptx
Unit-3 Practice Programs-5.docx
Inheritance
Keyword of java
Inheritance chepter 7
Binding,interface,abstarct class
Unit3 inheritance
Polymorphism presentation in java
polymorphismpresentation-160825122725.pdf

More from yugandhar vadlamudi (12)

ODP
Singleton pattern
PPT
Object Relational model for SQLIite in android
DOCX
JButton in Java Swing example
PPTX
Collections framework in java
PPTX
Packaes & interfaces
DOCX
JMenu Creation in Java Swing
DOCX
Adding a action listener to button
PPTX
Operators in java
PPTX
Inheritance
PPTX
Control flow statements in java
PPTX
Closer look at classes
PPTX
java Applet Introduction
Singleton pattern
Object Relational model for SQLIite in android
JButton in Java Swing example
Collections framework in java
Packaes & interfaces
JMenu Creation in Java Swing
Adding a action listener to button
Operators in java
Inheritance
Control flow statements in java
Closer look at classes
java Applet Introduction

Recently uploaded (20)

PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
TR - Agricultural Crops Production NC III.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Pre independence Education in Inndia.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PDF
Basic Mud Logging Guide for educational purpose
PDF
VCE English Exam - Section C Student Revision Booklet
Anesthesia in Laparoscopic Surgery in India
Microbial diseases, their pathogenesis and prophylaxis
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Microbial disease of the cardiovascular and lymphatic systems
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
TR - Agricultural Crops Production NC III.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Module 4: Burden of Disease Tutorial Slides S2 2025
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Pre independence Education in Inndia.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
FourierSeries-QuestionsWithAnswers(Part-A).pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
Basic Mud Logging Guide for educational purpose
VCE English Exam - Section C Student Revision Booklet

Dynamic method dispatch

  • 1. Dynamic Method Dispatch Abstract Class Using Final with inheritance
  • 2. Dynamic method dispatch • Dynamic method dispatch is one type of mechanism by which a call to an overridden method is resolved at run time • When an overridden method is called through the object of superclass then Java determines which version of that method to execute, based upon the type of the object being referred to at the time the call occurs, hence determination is made at run time. • Go through the example below
  • 3. • /* * Dynamic Method Dispach */ class Class_A { void demo() { System.out.println("the class A method called"); } } class Class_B extends Class_A { void demo() { System.out.println("the class B method called"); } } public class inheritance { public static void main(String[] y) { Class_A a=new Class_A(); a.demo(); /* * The below one is called upcasting */ Class_A b=new Class_B(); b.demo(); a=b; a.demo(); } }
  • 4. Difference between Static binding and Dynamic binding in java ? • Static binding in Java occurs during compile time • dynamic binding occurs during runtime. • Overloaded methods are bonded using static binding • overridden methods are bonded using dynamic binding at runtime.
  • 5. Abstract classes • If a class contain any abstract method then the class is declared as abstract class. • An abstract class is never instantiated. • Although it does not provide 100% abstraction because it can also have concrete method. Syntax • Abstract class <class_name>{}
  • 6. Abstract method • Method that are declared without any body within an abstract class is known as abstract method. • The method body will be defined by its subclass Syntax Abstract return_type method_name(arguments list); /* * abstract class and method */ abstract class Demo_A { abstract void Demo();//abstract method } class Demo_B extends Demo_A { void Demo() { System.out.println("hello"); } } public class Abstract_Demo { public static void main(String[] y) { Demo_B b=new Demo_B(); b.Demo(); } }
  • 7. Abstract class with Concrete methods /* * abstract class and Concrete method */ abstract class Demo_A { abstract void Demo(); //abstract method void demo_a() //concrete method { System.out.println("the method of abstract class concrete method"); } } class Demo_B extends Demo_A { void Demo() { System.out.println("hello"); } } public class Abstract_Demo { public static void main(String[] y) { Demo_B b=new Demo_B(); b.Demo(); b.demo_a(); //Demo_A a=new Demo_A(); //a.demo_a(); /* * try to remove the above comments to under the concept */ /* * we can create refference variable for abstract classes */ Demo_A a=new Demo_B(); a.Demo(); } }
  • 8. Final method • A final method cannot be overridden • Which means even though a sub class can call the final method of parent class without any issues but it cannot override it class Super { final void demo() { System.out.println("hello"); } } class Sub_ extends Super { /*void demo() { System.out.println("hello world"); }*/ void demo_1() { System.out.println("hello world"); } } class Demo { public static void main(String[] y) { Sub_ s=new Sub_(); s.demo(); } }
  • 9. Final class • We cannot extend a final class prevent inheritance final class Super { void demo() { System.out.println("hello"); } } class Sub_ extends Super { void demo_1() { System.out.println("hello world"); } } class Demo { public static void main(String[] y) { Sub_ s=new Sub_(); } }