06-02-25 ----------- Q)What is binding in the context of a method? =>Associating/linking a method call with method definition is nothig but binding. =>binding is of two types. 1)static binding 2)dynamic binding Q)What is static binding? =>Associating the method call with the method definition if happens at compile time, it is known as compile time binding or early binding or static binding. Note:- When method overloading is implemented, static binding only is perfromed. Q)What is dynamic binding? =>Associating the method call with the method definition if happens at program's execution time, it is known as dynamic/runtime/late binding. =>JVM perfroms dynamic binding. =>3 conditions must be satisfied for dynamic binding to happen. 1)method overring to be implemented 2)super reference should reference the sub class object 3)method call should be made using super reference Q)What are the similarities between method overloading and method overriding? =>In both the cases method name is the same. =>Both participate in the implementation of polymorphism Q)What are the differences between method overloading and method overriding? Method Overloading Method overrriding ---------------------------------------------------------------------- 1)method signatures same are different 2) return type is return type of the methods insignificant should be the same 3)access modifier plays a role doesn't paly any role in method overloading 4)implements static participates in the implementation polymorphism of dynamic polymorphism ********************************************** Q)How to create "has-a" relation between two classes? =>by making the reference of one class as an instance variable in another class, has-a relationship is created. Q)How to create "use-a" relation between two classes? By making the reference of some class as parameter of the method another class use-a relation is created. For eg. class Car extends Vehicle{ Gear gear;//has-a relation void move(Fuel fuel){ //use-a relation } }