
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Explain the difference between static and dynamic binding in Java.
In static binding the method call is bonded with the method body at compile time. This is also known as early binding. This is done using static, private and, final methods.
Example
class Super{ public static void sample(){ System.out.println("This is the method of superclass"); } } Public class Sub extends Super{ Public static void sample(){ System.out.println("This is the method of subclass"); } Public static void main(String args[]){ Sub.sample() } }
Output
This is the method of subclass
In dynamic binding the method call is bonded with the method body at run time.This is also known as late binding. This is done using instance methods.
Example
class Super{ public void sample(){ System.out.println("This is the method of superclass"); } } Public class extends Super{ Public static void sample(){ System.out.println("This is the method of subclass"); } Public static void main(String args[]){ new Sub().sample() } }
Output
This is the method of subclass
- Related Questions & Answers
- Difference between Static binding and dynamic binding in Java
- Difference Between Static and Dynamic Binding
- Static binding and dynamic binding in Java
- What are differences between static binding and dynamic binding in Java?
- Static vs Dynamic Binding in Java
- Static binding vs Dynamic binding in C#
- Difference between Static and Dynamic Testing
- Difference between Static and Dynamic Web Pages
- Difference between Static Routing and Dynamic Routing
- Difference between Static SQL and Dynamic SQL
- What is the difference between static and dynamic polymorphism?
- Difference between Static IP Address and Dynamic IP Address
- What is dynamic binding in Java?
- Dynamic Binding in C#
- What is static binding in Java?
Advertisements