TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Tuesday, 7 April 2020

Static Binding And Dynamic Binding | Static Binding And Dynamic Binding In System Program

Static Binding and Dynamic Binding

Connecting a method call to the method body is known as binding.

There are two types of binding

1.    Static Binding (also known as Early Binding).

2.    Dynamic Binding (also known as Late Binding).

Static Binding VS Dynamic Binding
Fig: Static VS Dynamic Binding

UnderStanding Type:

Types of instance

1) variables have a type

Each variable has a type, it may be primitive and non-primitive.
     int data=30;  

2) References have a type

   class Dog{  
   public static void main(String args[]){  
    Dog d1;//Here d1 is a type of Dog  
    }  
}  

3) Objects have a type

An object is an instance of particular java class,but it is also an
 instance of its superclass.
     class Animal{}  
  
    class Dog extends Animal{  
   public static void main(String args[]){  
    Dog d1=new Dog();  
     }  
}  

 Static Binding

When type of the object is determined at compiled time(by the compiler), it is known as static binding.
If there is any private, final or static method in a class, there is static binding.

Example of static binding

   class Dog{  
    private void eat(){System.out.println("dog is eating...");}  
           
    public static void main(String args[]){  
    Dog d1=new Dog();  
    d1.eat();  
   } }  

Dynamic Binding

When type of the object is determined at run-time, it is known as dynamic binding.

Example of dynamic binding

   class Animal{  
   void eat(){System.out.println("animal is eating...");}  
}  
  
   class Dog extends Animal{  
    void eat(){System.out.println("dog is eating...");}  
  
   public static void main(String args[]){  
    Animal a=new Dog();  
    a.eat();  
    }  
}  

   Output:

   dog is eating….

early and late binding
Fig: Early VS Late binding





No comments:

Post a Comment