Sampath Kumar S Assistant Professor, SECE

Slides:



Advertisements
Similar presentations
INHERITANCE BASICS Reusability is achieved by INHERITANCE
Advertisements

METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
1 Lecture 3 Inheritance. 2 A class that is inherited is called superclass The class that inherits is called subclass A subclass is a specialized version.
Polymorphism. Legal assignments Widening is legal Narrowing is illegal (unless you cast) class Test { public static void main(String args[]) { double.
Inheritance and Polymorphism Recitation 04/10/2009 CS 180 Department of Computer Science, Purdue University.
Inheritance and Polymorphism Recitation – 10/(16,17)/2008 CS 180 Department of Computer Science, Purdue University.
Inheritance, Static and Dynamic Typing. Announcements  Project 0 due Fri 2/13 at 11:59pm 24 slip hours (unused hours roll over)  HW3 released tonight,
CMSC 202 Interfaces. 11/20102 Classes and Methods When a class defines its methods as public, it describes how the class user interacts with the method.
Programming With Java ICS201 University Of Ha’il1 Chapter 8 Polymorphism and Abstract Classes.
Inheritance. Introduction Inheritance is one of the cornerstones of object-oriented programming because it allows the creation of hierarchical classifications.
Inheritance and Polymorphism Daniel Liang, Introduction to Java Programming.
Polymorphism. 3 main programming mechanisms that constitute OOP: 1. Encapsulation 2. Inheritance 3. Polymorphism.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
Inheritance & Dynamic Binding. Class USBFlashDrive We better introduce a new class USMBFlashDrive and save() is defined as a method in that class Computer.
Bayu Priyambadha, S.Kom. * Poly = Many, Morph = form * Polymorphism refers to a principle in biology in which an organism or species can have many different.
1 CS2136: Paradigms of Computation Class 14: Static & Final Parameters Overloading, Overriding, and Polymorphism Copyright 2001, 2002, 2003 Michael J.
ICBT  Basura Ramanayaka  Eshani werapitiya  Hasitha Dananjaya.
Java Applets and other things. Applets Very like usual classes Use init() method instead of main Applets provide 4 methods init() start() stop() destroy()
10 Polymorphism. 2 Contents Defining Polymorphism Method Overloading Method Overriding Early Binding and Late Binding Implementing Polymorphism.
1 Chapter 9a Abstract Classes & Dynamic Binding. 2 Abstract Classes All classes so far have been concrete classes –Classes that can be used to create.
Inheritance in Java. Access Specifiers private keywordprivate keyword –Used for most instance variables –private variables and methods are accessible.
Java Programming Final Keyword In Java. final keyword The final keyword in java is used to restrict the user. The final keyword can be used in many context.
CMSC 202 Polymorphism. 10/20102 Topics Binding (early and late) Upcasting and downcasting Extensibility The final modifier with  methods  classes.
Methods.
CH10 Supplementary Material Prepared by Fatimah Alakeel Oct 2010.
BY:- TOPS Technologies
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
Modern Programming Tools And Techniques-I
Programming in Java, 2e Sachin Malhotra Saurabh Choudhary.
Abstract Classes and Interfaces
COMPUTER 2430 Object Oriented Programming and Data Structures I
Overriding Method.
Lecture 17: Polymorphism (Part II)
ATS Application Programming: Java Programming
Modern Programming Tools And Techniques-I Inheritance
תוכנה 1 תרגול מספר 11: Static vs. Dynamic Binding
More inheritance, Abstract Classes and Interfaces
مظفر بگ محمدی دانشگاه ایلام
CMSC 202 Interfaces.
Sampath Kumar S Assistant Professor, SECE
Polymorphism CT1513.
CMSC 202 Polymorphism.
Sampath Kumar S Assistant Professor, SECE
Sampath Kumar S Assistant Professor, SECE
METHOD OVERRIDING in JAVA
S.VIGNESH Assistant Professor/CSE, SECE
CS18000: Problem Solving and Object-Oriented Programming
Sampath Kumar.S Assistant Professor/IT, SECE
S.VIGNESH Assistant Professor, SECE
Sampath Kumar S Assistant Professor, SECE/IT
Method Overloading in JAVA
Sampath Kumar S Assistant Professor, SECE
Inheritance Inheritance is a fundamental Object Oriented concept
Method Overriding in Java
Sampath Kumar S Assistant Professor, SECE
Graphics Programming - Frames
Input and Output Stream
Sampath Kumar S Assistant Professor, SECE
مظفر بگ محمدی دانشگاه ایلام
class PrintOnetoTen { public static void main(String args[]) {
CMSC 202 Interfaces.
Polymorphism.
Chapter 9 Carrano Chapter 10 Small Java
Developing Java Applications with NetBeans
Chapter 11 Inheritance and Polymorphism Part 1
Sampath Kumar S Assistant Professor, SECE
CMSC 202 Interfaces.
Advanced Programming in Java
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

Sampath Kumar S Assistant Professor, SECE Dynamic Binding Sampath Kumar S Assistant Professor, SECE

Binding 4/24/2019 Connecting a method call to the method body is known as binding. There are two types of binding Static binding (also known as early binding). Dynamic binding (also known as late binding) Sampath Kumar S, AP

Type of instance 4/24/2019 1) variables have a type Each variable has a type, it may be primitive and non-primitive. int data=30; Here data variable is a type of int. 2) References have a type class Dog{ public static void main(String args[]){ Dog d1;//Here d1 is a type of Dog } } Sampath Kumar S, AP

4/24/2019 Cont.., 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(); } } Here d1 is an instance of Dog class, but it is also an instance of Animal. Sampath Kumar S, AP

4/24/2019 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. Sampath Kumar S, AP

Example of static binding 4/24/2019 class Dog{ private void eat(){ System.out.println("Dog is eating");} public static void main(String args[]){ Dog d1=new Dog(); d1.eat(); } } Output: Dog is eating Sampath Kumar S, AP

4/24/2019 Dynamic binding When type of the object is determined at run-time, it is known as dynamic binding. Sampath Kumar S, AP

Example of dynamic binding 4/24/2019 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(); } } Note: Here object type cannot be determined by the compiler, because the instance of Dog is also an instance of Animal. So compiler doesn't know its type, only its base type. Output: Dog is eating Sampath Kumar S, AP

4/24/2019 Sampath Kumar S, AP

4/24/2019 Thank You  Sampath Kumar S, AP