SlideShare a Scribd company logo
1 of 14
Static and Dynamic binding
Static Binding: it is also known as early binding the compiler resolve the
binding at compile time. all static method call is resolved at compile time
itself. Because static method are class method and they are accessed using
class name itself. Hence there is no confusion for compiler to resolve. which
version of method is going to call.
Class A
{
Publicstatic voidA1()
{
S.O.P(“”Iam inA”);
}
}
Class B extendsA
{
Publicstatic voidA1()
{
S.O.P(‘Iam inB”);
}
}
Class C extendsB
{
Publicstatic voidA1()
{
S.O.P(“Iam in C”);
}
}
Class TT
{
Publicstatic voidmain(Stringarr[])
{
A a= new C();//methodcall is statically bindedso
it will call at compile time itselfand printClass A
a.A1(); //method
B.A1()//use of class name to access the static
method
}
}
Dynamic Binding: dynamic binding also known as late binding it
means method implementation that actually determined at run time
and not at compile time.
Class A
{
Publicdoit()
{
S.O.P(“Iam in A”);
}
}
Class B extendsA
{
Publicdoit()
{
Another example ofdynamic bindinggivenas
class A1
{
void who()
{
System.out.println("i aminAAA");
}
}
class B1 extendsA1
{
S.O.P(“Iam in B”);
}
}
Class C extendsB
{
Publicdoit()
{
S.O.P(“Iam in C”);
}
}
Class Test
{
Publicstatic voidmain(Stringarr[])
{
A x= newB();
x.doit();// it will print I am in B
}}
void who()
{
System.out.println("i amoinBBB");
}
}
class C1 extendsB1
{
void who()
{
System.out.println("i amincc");
}
}
class Dynamicbinding
{
publicstatic voidmain(Stringarr[])
{
A1 a=new B1();
a.who();
}
}
Note: x is reference variableof object of type A but it is instantiated an object of
Class B because of new B().JREwill look at this statement and say even though x
is clearly declaredas type A,it is instantiatedas an object of class B, so it will run
the version of doit method that is defined.
UNIT-3
Abstract Method and Abstract class:
It is an method without implementationit representswhat tobe done. but does
not specify how it will be done.
Any class which contains one or more abstract method is defined as abstract
class.
An abstract class has following characteristics’.
1. It cannot be instantiated(i.e its object is not created).
2. It forces all its subclasses to provide the implementation of its abstract
method.
If any subclass does not provide implementation of even a single
abstract method of super class then subclass is also declared as abstract.
e.g
abstract class A
{
Abstract voidcallMe(); //abstract
method
{
Class B extendsA
{ Void callMe()
{
S.O.P(“thisisa call for me”);
}
Public static void main(Stringarr[])
{
B b= new B();
b.callMe();
}
}
Note:
1. Abstract class isnot interface.
2. An abstract class must have an abstract method
3. Abstract class can have constructor, membervariable and normal methods.
4. Abstract classescan neverbe instantiated.
5. When you extend abstract class with abstract method you must define the
abstract method in child class. or make child class abstract.
Abstract isan important feature of OOPs.it means hiding complexity. Abstract
class used to provide abstraction.
Example: we are casting instance of car type under Vehicle .now vehicle
reference can be used to provide implementation but it will hide the
actual implementation process.
abstract class vehicle
{
public abstract void engine();
}
public class Car extends Vehicle
{
public static void main(String arr[])
{
Vehicle v=new Car();
v.engine();
}
}
Public void engine()
{
System.out.println(“Car engine”);
//here you can write any other code
}
Output: car Engine
Abstract methods are usually declared where two or more subclasses are expected to do
similar things in different ways through different implementation.
These subclasses extend the same abstract class and provide different implementation for
abstract method.
INTERFACE:
Interface is collectionof abstract methods andstatic final data members.
Interface cannot be instantiatedbut their reference variablecanbe created.
Syntax:
interface identifier
{
Static final data members;
Implicit abstract method();
}
e.g.
interface Printable
{
Void print ();
}
Interface is implemented by class. If a class implements’ an interface then it
need to provide public definition of all interface methods. Otherwise class is
made abstract
Syntax of implementation:
Class identifier implements interface-
name
{
Public definition of interface method;
Additional method of class
}
e.g
Class A implements Printable
{
Public void print ()
{
S.O.P(“A is printable”);
}
}
Difference between class and interface
{
Class interface
Degree of abstraction:
Class support Zero to 100 %
abstraction.i.e. in a class we can have all
abstract have all abstract methods all non
abstract method or both combination
Interface support only 100% abstraction
i.e. they can only have abstract methods
Type of inheritance:
Class facilitate feature based inheritance
(all part of class is inherited in another
class) in java as well as in life multiple
feature based inheritance is not
supported.
It facilitate role based inheritance (only
specific part of class is called).in java as
well as in real life multiple role based
inheritance is supported.
Inheritance Purpose Analogy
Feature based
inheritance
Code reusability and run
time polymorphism
Represent blood relation
of real life .A is son of
B.in such relation both
feature and name of is
inherited from single
family.i.e multiple
feature based
inheritance is not
supported in real life .
same is the case with
java
Role based inheritance
Run time polymorphism Represent non blood
relations of real life . e.g
A is friend of C and C is a
doctor . in such realtion
only name is inherited .
each name represents a
role in real life multiple
role is played by same
person i.e multiple role
based inheritance .
If a class impliments interface then interface name is inherited by the class
e.g
public interface Doable
{
Void canbeDone();
}
Class A impliments Doable
{
Public void canbe Done()
{
;;;;;
}
}
Now A is Doable
From figure we can found that Krishnais playing different role at different
instance.
During software development programmers needtorefer classes of other
programmers class can be referencedinthe following three ways.
1. By Name(we canaccess the instance variable andmethod using class
name)
2. By family(inheritance is the best example)
3. By Role(we needinterfacehere)
1.inthe first approach a class is directly referencedby its name . in this
approach in order to refer the class its name must be known available
classes is calledstatic class environment referencing andreferencedclass.
Tight coupling createdthe maintenance problem.
e.g
let the programmer A and B who are working on a software.
Programmer A is assignedaclass name one
Programmer B is assigneda class name two
Class one is simple and A will nedd only 10 hours to complete.
Class twois complex and B nedd10 days to complete.
Class one has a dependence onclass two
krishna
VISHNU
DWARKADHES
H
VASUDEV
KAHANA
Class one
{
Public static voidinvoke(twox)
{
x.display();
}
}
Class two
{
/will complete in10 days
}
Limitation:
 A needtowait till completionof class two in order to complete his
class.
 If B changes name of his class. A will require tomodify his
class(tight coupling)
2.By Family:
Class one
{
Public static void
invoke(canbeDisplayed x)
{
x.display();
}
Abstract class canbeDisplayed
{
Abstract void display()
}
Class twoextends canbeDisplayed
{
/will complete in10 days
}
Advantage:
 Unknown and unavailable classes canbe referencedas long as they are
part of referencedfamily.
 Name of referenceclasses canbe changedwithout affecting the reference
class
Disadvantage:
 Top most class of family must be known and available.
 Facility of referencing unknownand unavailable class is combinedto
one family
3.By Role:
Class one
{
Public static void
invoke(canbeDisplayed x)
{
x.display();//completedin10 min
;;;;;;;;;;;;;;;;;;;;;
}
Interface canbeDisplayed
{
Void disaplay() //completedin10 min
}
Class twoimpliments canbeDisplayed
{
//completedin10 days
}
Advantages:
1. Any class belongs toany family which plays the referenced role canbe
referenced. this facility of referencing unknownand unavailable classes is
calleddynamic classing environment.
2. Only the role nedd to be known torefrence class
3. Role basedreference creates loosecoupling between refrencing and
refrencedclass.
Following use case demonstrate the neddof role basedinheritance i.e
requirement of only name in inheritance.
Let there are three programmer namedA ,B and C A is defining a class
named PQR whichconatins P,Q,and R methods.
A needtoexpose only method P of this class toClass B.
And only method Q toclass C
Let A can achieve his object only as
Claa of A interface Class of B
Class PQR impliments
P,Q
{
Public void P()
{
;;;;;;;;;;;;;
Interface P
{
Void P()
}
Interface Q
{
Class Puser
{
Public static void
invoke(P x)
{
x.P();
‘’’’’’
}
Public void Q()
{
;;;;;;;;;;;;;;
;;;;;;;;;;;;;;
}
Public void R()
{
;;;;;;;;;;;;
;;;;;;;;;;;;;
}
}
Void Q
{
Void Q();
}
;;;;;;;;;;;;
}
}
Class of C
Class Quser
{
Public static void
invoke(Q x)
{
Public static void
invoke(Q x)
{
x.Q();
;;;;;;;;;;;;;;;;;;;
}
}
Example of interface:there are twointerfaces one for whattype and one
for vegetable class. Throughthese twointerfaces we candecide what
type of fruit or vegetable has.
interface Fruit {
public booleanhasAPeel();
//has a peel must be implementedinany
class implementing Fruit
//methods ininterfaces must be public
}
interface Vegetable{
public booleanisARoot();
//is a root must be implementedinany
class implementing Vegetable
//methods ininterfaces must be public
}
class whattype{
class Subtraction
implements Subb
{
public int sub(int x,int y)
{
returnx-y;
}
public float sub(float
x,float y)
{
returnx-y;
}
static String doesThisHaveAPeel(Fruit
fruitIn)
{
if (fruitIn.hasAPeel())
return"This has a peel";
else
return"This does not have a peel";
}
static String isThisARoot(Vegetable
vegetableIn)
{
if (vegetableIn.isARoot())
return"This is a root";
else
return"This is not a root";
}
static String
doesThisHaveAPeelOrIsThisRoot(
Tomato tomatoIn)
{
if (tomatoIn.hasAPeel() &&
tomatoIn.isARoot())
return"This bothhas a peel and is a
root";
else if (tomatoIn.hasAPeel() ||
tomatoIn.isARoot())
return"This either has a peel or is a
root";
else
return"This neither has a peel or is a
root";
}
}
class Tomato implements Fruit, Vegetable {
booleanpeel = false;
booleanroot = false;
public double
sub(double x , double y)
{
returnx-y;
}
}
class Math
{
public static void
main(String arr[])
{
Addd a1=new
Addition();
Subb a11= new
Subtraction();
System.out.println("add
ition
is="+a1.Add(10,29));
System.out.println("sub
traction
is="+a1.sub(20,12));
System.out.println("sub
traction
is="+a11.sub(20.0,12.0))
;
}
}
Example:make the
interface for addition
and subtractionand
access the classes with
various methods in it.
public Tomato() {}
public booleanhasAPeel()
//must have this method,
// because Fruit declaredit
{
returnpeel;
}
public booleanisARoot()
//must have this method,
// because Vegetable declaredit
{
returnroot;
}
public static voidmain(String[]args) {
//Part one: making a tomato
Tomato tomato= new Tomato();
System.out.println(whattype.isThisARoot(t
omato));
//output is:This is not a root
System.out.println(
whattype.doesThisHaveAPeel(tomato));
//output is:This does not have a peel
System.out.println
(whattype.doesThisHaveAPeelOrIsThisRoot
(tomato));
//output is:This neither has a peel or is
a root
//Part two: making a fruit
//Fruit = newFruit();
//can not instantiate aninterface like
// this because Fruit is not a class
interface Addd
{
public int Add(int x,int
y);
public int sub(int a,int
b);
}
interface Subb
{
public double
sub(double x,double y);
}
class Addition
implements Addd
{
public int Add(int x,int y)
{
returnx+y;
}
public int sub(int x,int y)
{
returnx-y;
}
public float Add( float x
,float y)
{
returnx+y;
}
public double
Add(double x , double y,
double z)
{
returnx+y+z;
Fruit tomatoFruit =new Tomato();
//can instantiate by interface like
// this because Tomato is a class
//System.out.println(
//
FandVUtility.isThisARoot(tomatoFruit));
//can not treat tomatoFruit as a
Vegetable
// without casting it to a Vegetable or
Tomato
System.out.println(
whattype.doesThisHaveAPeel(tomatoFruit)
);
//output is:This does not have a peel
//System.out.println
//
(whattype.doesThisHaveAPeelOrIsThisRoot
// (tomatoFruit));
//can not treat tomatoFruit as a
Vegetable
// without casting it to a Vegetable or
Tomato
}
}
}
}
Example:write a
program to calculate
area of class rectangle
and class triangle
throughinterface .
class Rectangle
{
public float
compute(float x, float y)
{
return(x *y);
}
}
class Triangle
{
public float
compute(float x,float y)
{
return(x *y/2);
}
}
class InterfaceArea
{
public static void
main(String args[])
{
Rectangle rect =new
Rectangle();
Triangle tri = new
Triangle();
System.out.println("Are
a Of Rectangle ="+
rect.compute(1,2));
System.out.println("Are
a Of Triangle = "+
tri.compute(10,2));
}
}

More Related Content

What's hot (20)

Interface in java
Interface in javaInterface in java
Interface in java
 
Interface
InterfaceInterface
Interface
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Java interface
Java interfaceJava interface
Java interface
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Interfaces c#
Interfaces c#Interfaces c#
Interfaces c#
 
Java interfaces & abstract classes
Java interfaces & abstract classesJava interfaces & abstract classes
Java interfaces & abstract classes
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and Interface
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Java interface
Java interfaceJava interface
Java interface
 
Interfaces in JAVA !! why??
Interfaces in JAVA !!  why??Interfaces in JAVA !!  why??
Interfaces in JAVA !! why??
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
9781111530532 ppt ch10
9781111530532 ppt ch109781111530532 ppt ch10
9781111530532 ppt ch10
 
Interfaces and abstract classes
Interfaces and abstract classesInterfaces and abstract classes
Interfaces and abstract classes
 
Dynamic method dispatch
Dynamic method dispatchDynamic method dispatch
Dynamic method dispatch
 
L7 inheritance
L7 inheritanceL7 inheritance
L7 inheritance
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Ganesh groups
Ganesh groupsGanesh groups
Ganesh groups
 
Java: Inheritance
Java: InheritanceJava: Inheritance
Java: Inheritance
 
Abstract class
Abstract classAbstract class
Abstract class
 

Similar to Binding,interface,abstarct class

Exception handling and packages.pdf
Exception handling and packages.pdfException handling and packages.pdf
Exception handling and packages.pdfKp Sharma
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritanceArjun Shanka
 
abstract,final,interface (1).pptx upload
abstract,final,interface (1).pptx uploadabstract,final,interface (1).pptx upload
abstract,final,interface (1).pptx uploaddashpayal697
 
Inheritance and interface
Inheritance and interfaceInheritance and interface
Inheritance and interfaceShubham Sharma
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)ssuser7f90ae
 
Xamarin: Namespace and Classes
Xamarin: Namespace and ClassesXamarin: Namespace and Classes
Xamarin: Namespace and ClassesEng Teong Cheah
 
Session 6_Java Interfaces_Details_Programs.pdf
Session 6_Java Interfaces_Details_Programs.pdfSession 6_Java Interfaces_Details_Programs.pdf
Session 6_Java Interfaces_Details_Programs.pdfTabassumMaktum
 
Session 6_Interfaces in va examples .ppt
Session 6_Interfaces in va examples .pptSession 6_Interfaces in va examples .ppt
Session 6_Interfaces in va examples .pptTabassumMaktum
 
Session 6_Interfaces in va examples .ppt
Session 6_Interfaces in va examples .pptSession 6_Interfaces in va examples .ppt
Session 6_Interfaces in va examples .pptTabassumMaktum
 
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptxSodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptxRudranilDas11
 
Lecture 8 abstract class and interface
Lecture   8 abstract class and interfaceLecture   8 abstract class and interface
Lecture 8 abstract class and interfacemanish kumar
 
Object Oriented Programming - Inheritance
Object Oriented Programming - InheritanceObject Oriented Programming - Inheritance
Object Oriented Programming - InheritanceDudy Ali
 

Similar to Binding,interface,abstarct class (20)

Exception handling and packages.pdf
Exception handling and packages.pdfException handling and packages.pdf
Exception handling and packages.pdf
 
java-06inheritance
java-06inheritancejava-06inheritance
java-06inheritance
 
Java 06
Java 06Java 06
Java 06
 
Interfaces
InterfacesInterfaces
Interfaces
 
abstract,final,interface (1).pptx upload
abstract,final,interface (1).pptx uploadabstract,final,interface (1).pptx upload
abstract,final,interface (1).pptx upload
 
Design pattern
Design patternDesign pattern
Design pattern
 
Inheritance and interface
Inheritance and interfaceInheritance and interface
Inheritance and interface
 
21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)21UCAC31 Java Programming.pdf(MTNC)(BCA)
21UCAC31 Java Programming.pdf(MTNC)(BCA)
 
Xamarin: Namespace and Classes
Xamarin: Namespace and ClassesXamarin: Namespace and Classes
Xamarin: Namespace and Classes
 
Session 6_Java Interfaces_Details_Programs.pdf
Session 6_Java Interfaces_Details_Programs.pdfSession 6_Java Interfaces_Details_Programs.pdf
Session 6_Java Interfaces_Details_Programs.pdf
 
Session 6_Interfaces in va examples .ppt
Session 6_Interfaces in va examples .pptSession 6_Interfaces in va examples .ppt
Session 6_Interfaces in va examples .ppt
 
Session 6_Interfaces in va examples .ppt
Session 6_Interfaces in va examples .pptSession 6_Interfaces in va examples .ppt
Session 6_Interfaces in va examples .ppt
 
Inheritance
InheritanceInheritance
Inheritance
 
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptxSodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
SodaPDF-converted-inheritanceinjava-120903114217-phpapp02-converted.pptx
 
Inheritance
InheritanceInheritance
Inheritance
 
Lecture 8 abstract class and interface
Lecture   8 abstract class and interfaceLecture   8 abstract class and interface
Lecture 8 abstract class and interface
 
Interface in java
Interface in javaInterface in java
Interface in java
 
JAVA.pptx
JAVA.pptxJAVA.pptx
JAVA.pptx
 
14 interface
14  interface14  interface
14 interface
 
Object Oriented Programming - Inheritance
Object Oriented Programming - InheritanceObject Oriented Programming - Inheritance
Object Oriented Programming - Inheritance
 

More from vishal choudhary (20)

SE-Lecture1.ppt
SE-Lecture1.pptSE-Lecture1.ppt
SE-Lecture1.ppt
 
SE-Testing.ppt
SE-Testing.pptSE-Testing.ppt
SE-Testing.ppt
 
SE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.pptSE-CyclomaticComplexityand Testing.ppt
SE-CyclomaticComplexityand Testing.ppt
 
SE-Lecture-7.pptx
SE-Lecture-7.pptxSE-Lecture-7.pptx
SE-Lecture-7.pptx
 
Se-Lecture-6.ppt
Se-Lecture-6.pptSe-Lecture-6.ppt
Se-Lecture-6.ppt
 
SE-Lecture-5.pptx
SE-Lecture-5.pptxSE-Lecture-5.pptx
SE-Lecture-5.pptx
 
XML.pptx
XML.pptxXML.pptx
XML.pptx
 
SE-Lecture-8.pptx
SE-Lecture-8.pptxSE-Lecture-8.pptx
SE-Lecture-8.pptx
 
SE-coupling and cohesion.ppt
SE-coupling and cohesion.pptSE-coupling and cohesion.ppt
SE-coupling and cohesion.ppt
 
SE-Lecture-2.pptx
SE-Lecture-2.pptxSE-Lecture-2.pptx
SE-Lecture-2.pptx
 
SE-software design.ppt
SE-software design.pptSE-software design.ppt
SE-software design.ppt
 
SE1.ppt
SE1.pptSE1.ppt
SE1.ppt
 
SE-Lecture-4.pptx
SE-Lecture-4.pptxSE-Lecture-4.pptx
SE-Lecture-4.pptx
 
SE-Lecture=3.pptx
SE-Lecture=3.pptxSE-Lecture=3.pptx
SE-Lecture=3.pptx
 
Multimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptxMultimedia-Lecture-Animation.pptx
Multimedia-Lecture-Animation.pptx
 
MultimediaLecture5.pptx
MultimediaLecture5.pptxMultimediaLecture5.pptx
MultimediaLecture5.pptx
 
Multimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptxMultimedia-Lecture-7.pptx
Multimedia-Lecture-7.pptx
 
MultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptxMultiMedia-Lecture-4.pptx
MultiMedia-Lecture-4.pptx
 
Multimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptxMultimedia-Lecture-6.pptx
Multimedia-Lecture-6.pptx
 
Multimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptxMultimedia-Lecture-3.pptx
Multimedia-Lecture-3.pptx
 

Recently uploaded

भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,Virag Sontakke
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 

Recently uploaded (20)

भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,भारत-रोम व्यापार.pptx, Indo-Roman Trade,
भारत-रोम व्यापार.pptx, Indo-Roman Trade,
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 

Binding,interface,abstarct class

  • 1. Static and Dynamic binding Static Binding: it is also known as early binding the compiler resolve the binding at compile time. all static method call is resolved at compile time itself. Because static method are class method and they are accessed using class name itself. Hence there is no confusion for compiler to resolve. which version of method is going to call. Class A { Publicstatic voidA1() { S.O.P(“”Iam inA”); } } Class B extendsA { Publicstatic voidA1() { S.O.P(‘Iam inB”); } } Class C extendsB { Publicstatic voidA1() { S.O.P(“Iam in C”); } } Class TT { Publicstatic voidmain(Stringarr[]) { A a= new C();//methodcall is statically bindedso it will call at compile time itselfand printClass A a.A1(); //method B.A1()//use of class name to access the static method } } Dynamic Binding: dynamic binding also known as late binding it means method implementation that actually determined at run time and not at compile time. Class A { Publicdoit() { S.O.P(“Iam in A”); } } Class B extendsA { Publicdoit() { Another example ofdynamic bindinggivenas class A1 { void who() { System.out.println("i aminAAA"); } } class B1 extendsA1 {
  • 2. S.O.P(“Iam in B”); } } Class C extendsB { Publicdoit() { S.O.P(“Iam in C”); } } Class Test { Publicstatic voidmain(Stringarr[]) { A x= newB(); x.doit();// it will print I am in B }} void who() { System.out.println("i amoinBBB"); } } class C1 extendsB1 { void who() { System.out.println("i amincc"); } } class Dynamicbinding { publicstatic voidmain(Stringarr[]) { A1 a=new B1(); a.who(); } } Note: x is reference variableof object of type A but it is instantiated an object of Class B because of new B().JREwill look at this statement and say even though x is clearly declaredas type A,it is instantiatedas an object of class B, so it will run the version of doit method that is defined. UNIT-3 Abstract Method and Abstract class: It is an method without implementationit representswhat tobe done. but does not specify how it will be done. Any class which contains one or more abstract method is defined as abstract class.
  • 3. An abstract class has following characteristics’. 1. It cannot be instantiated(i.e its object is not created). 2. It forces all its subclasses to provide the implementation of its abstract method. If any subclass does not provide implementation of even a single abstract method of super class then subclass is also declared as abstract. e.g abstract class A { Abstract voidcallMe(); //abstract method { Class B extendsA { Void callMe() { S.O.P(“thisisa call for me”); } Public static void main(Stringarr[]) { B b= new B(); b.callMe(); } } Note: 1. Abstract class isnot interface. 2. An abstract class must have an abstract method 3. Abstract class can have constructor, membervariable and normal methods. 4. Abstract classescan neverbe instantiated. 5. When you extend abstract class with abstract method you must define the abstract method in child class. or make child class abstract. Abstract isan important feature of OOPs.it means hiding complexity. Abstract class used to provide abstraction. Example: we are casting instance of car type under Vehicle .now vehicle reference can be used to provide implementation but it will hide the actual implementation process. abstract class vehicle { public abstract void engine(); } public class Car extends Vehicle { public static void main(String arr[]) { Vehicle v=new Car(); v.engine(); } }
  • 4. Public void engine() { System.out.println(“Car engine”); //here you can write any other code } Output: car Engine Abstract methods are usually declared where two or more subclasses are expected to do similar things in different ways through different implementation. These subclasses extend the same abstract class and provide different implementation for abstract method. INTERFACE: Interface is collectionof abstract methods andstatic final data members. Interface cannot be instantiatedbut their reference variablecanbe created. Syntax: interface identifier { Static final data members; Implicit abstract method(); } e.g. interface Printable { Void print (); } Interface is implemented by class. If a class implements’ an interface then it need to provide public definition of all interface methods. Otherwise class is made abstract Syntax of implementation:
  • 5. Class identifier implements interface- name { Public definition of interface method; Additional method of class } e.g Class A implements Printable { Public void print () { S.O.P(“A is printable”); } } Difference between class and interface { Class interface Degree of abstraction: Class support Zero to 100 % abstraction.i.e. in a class we can have all abstract have all abstract methods all non abstract method or both combination Interface support only 100% abstraction i.e. they can only have abstract methods Type of inheritance: Class facilitate feature based inheritance (all part of class is inherited in another class) in java as well as in life multiple feature based inheritance is not supported. It facilitate role based inheritance (only specific part of class is called).in java as well as in real life multiple role based inheritance is supported. Inheritance Purpose Analogy Feature based inheritance Code reusability and run time polymorphism Represent blood relation of real life .A is son of
  • 6. B.in such relation both feature and name of is inherited from single family.i.e multiple feature based inheritance is not supported in real life . same is the case with java Role based inheritance Run time polymorphism Represent non blood relations of real life . e.g A is friend of C and C is a doctor . in such realtion only name is inherited . each name represents a role in real life multiple role is played by same person i.e multiple role based inheritance . If a class impliments interface then interface name is inherited by the class e.g public interface Doable { Void canbeDone(); } Class A impliments Doable { Public void canbe Done() { ;;;;; } } Now A is Doable
  • 7. From figure we can found that Krishnais playing different role at different instance. During software development programmers needtorefer classes of other programmers class can be referencedinthe following three ways. 1. By Name(we canaccess the instance variable andmethod using class name) 2. By family(inheritance is the best example) 3. By Role(we needinterfacehere) 1.inthe first approach a class is directly referencedby its name . in this approach in order to refer the class its name must be known available classes is calledstatic class environment referencing andreferencedclass. Tight coupling createdthe maintenance problem. e.g let the programmer A and B who are working on a software. Programmer A is assignedaclass name one Programmer B is assigneda class name two Class one is simple and A will nedd only 10 hours to complete. Class twois complex and B nedd10 days to complete. Class one has a dependence onclass two krishna VISHNU DWARKADHES H VASUDEV KAHANA
  • 8. Class one { Public static voidinvoke(twox) { x.display(); } } Class two { /will complete in10 days } Limitation:  A needtowait till completionof class two in order to complete his class.  If B changes name of his class. A will require tomodify his class(tight coupling) 2.By Family: Class one { Public static void invoke(canbeDisplayed x) { x.display(); } Abstract class canbeDisplayed { Abstract void display() } Class twoextends canbeDisplayed { /will complete in10 days } Advantage:  Unknown and unavailable classes canbe referencedas long as they are part of referencedfamily.  Name of referenceclasses canbe changedwithout affecting the reference class Disadvantage:  Top most class of family must be known and available.  Facility of referencing unknownand unavailable class is combinedto one family
  • 9. 3.By Role: Class one { Public static void invoke(canbeDisplayed x) { x.display();//completedin10 min ;;;;;;;;;;;;;;;;;;;;; } Interface canbeDisplayed { Void disaplay() //completedin10 min } Class twoimpliments canbeDisplayed { //completedin10 days } Advantages: 1. Any class belongs toany family which plays the referenced role canbe referenced. this facility of referencing unknownand unavailable classes is calleddynamic classing environment. 2. Only the role nedd to be known torefrence class 3. Role basedreference creates loosecoupling between refrencing and refrencedclass. Following use case demonstrate the neddof role basedinheritance i.e requirement of only name in inheritance. Let there are three programmer namedA ,B and C A is defining a class named PQR whichconatins P,Q,and R methods. A needtoexpose only method P of this class toClass B. And only method Q toclass C Let A can achieve his object only as Claa of A interface Class of B Class PQR impliments P,Q { Public void P() { ;;;;;;;;;;;;; Interface P { Void P() } Interface Q { Class Puser { Public static void invoke(P x) { x.P();
  • 10. ‘’’’’’ } Public void Q() { ;;;;;;;;;;;;;; ;;;;;;;;;;;;;; } Public void R() { ;;;;;;;;;;;; ;;;;;;;;;;;;; } } Void Q { Void Q(); } ;;;;;;;;;;;; } } Class of C Class Quser { Public static void invoke(Q x) { Public static void invoke(Q x) { x.Q(); ;;;;;;;;;;;;;;;;;;; } } Example of interface:there are twointerfaces one for whattype and one for vegetable class. Throughthese twointerfaces we candecide what type of fruit or vegetable has. interface Fruit { public booleanhasAPeel(); //has a peel must be implementedinany class implementing Fruit //methods ininterfaces must be public } interface Vegetable{ public booleanisARoot(); //is a root must be implementedinany class implementing Vegetable //methods ininterfaces must be public } class whattype{ class Subtraction implements Subb { public int sub(int x,int y) { returnx-y; } public float sub(float x,float y) { returnx-y; }
  • 11. static String doesThisHaveAPeel(Fruit fruitIn) { if (fruitIn.hasAPeel()) return"This has a peel"; else return"This does not have a peel"; } static String isThisARoot(Vegetable vegetableIn) { if (vegetableIn.isARoot()) return"This is a root"; else return"This is not a root"; } static String doesThisHaveAPeelOrIsThisRoot( Tomato tomatoIn) { if (tomatoIn.hasAPeel() && tomatoIn.isARoot()) return"This bothhas a peel and is a root"; else if (tomatoIn.hasAPeel() || tomatoIn.isARoot()) return"This either has a peel or is a root"; else return"This neither has a peel or is a root"; } } class Tomato implements Fruit, Vegetable { booleanpeel = false; booleanroot = false; public double sub(double x , double y) { returnx-y; } } class Math { public static void main(String arr[]) { Addd a1=new Addition(); Subb a11= new Subtraction(); System.out.println("add ition is="+a1.Add(10,29)); System.out.println("sub traction is="+a1.sub(20,12)); System.out.println("sub traction is="+a11.sub(20.0,12.0)) ; } } Example:make the interface for addition and subtractionand access the classes with various methods in it.
  • 12. public Tomato() {} public booleanhasAPeel() //must have this method, // because Fruit declaredit { returnpeel; } public booleanisARoot() //must have this method, // because Vegetable declaredit { returnroot; } public static voidmain(String[]args) { //Part one: making a tomato Tomato tomato= new Tomato(); System.out.println(whattype.isThisARoot(t omato)); //output is:This is not a root System.out.println( whattype.doesThisHaveAPeel(tomato)); //output is:This does not have a peel System.out.println (whattype.doesThisHaveAPeelOrIsThisRoot (tomato)); //output is:This neither has a peel or is a root //Part two: making a fruit //Fruit = newFruit(); //can not instantiate aninterface like // this because Fruit is not a class interface Addd { public int Add(int x,int y); public int sub(int a,int b); } interface Subb { public double sub(double x,double y); } class Addition implements Addd { public int Add(int x,int y) { returnx+y; } public int sub(int x,int y) { returnx-y; } public float Add( float x ,float y) { returnx+y; } public double Add(double x , double y, double z) { returnx+y+z;
  • 13. Fruit tomatoFruit =new Tomato(); //can instantiate by interface like // this because Tomato is a class //System.out.println( // FandVUtility.isThisARoot(tomatoFruit)); //can not treat tomatoFruit as a Vegetable // without casting it to a Vegetable or Tomato System.out.println( whattype.doesThisHaveAPeel(tomatoFruit) ); //output is:This does not have a peel //System.out.println // (whattype.doesThisHaveAPeelOrIsThisRoot // (tomatoFruit)); //can not treat tomatoFruit as a Vegetable // without casting it to a Vegetable or Tomato } } } } Example:write a program to calculate area of class rectangle and class triangle throughinterface . class Rectangle { public float compute(float x, float y) { return(x *y); } } class Triangle { public float compute(float x,float y) { return(x *y/2); } } class InterfaceArea { public static void main(String args[]) { Rectangle rect =new Rectangle(); Triangle tri = new Triangle();
  • 14. System.out.println("Are a Of Rectangle ="+ rect.compute(1,2)); System.out.println("Are a Of Triangle = "+ tri.compute(10,2)); } }