question archive 1) Explain the use of dynamic binding in object-oriented programming
Subject:Computer SciencePrice:3.86 Bought12
1) Explain the use of dynamic binding in object-oriented programming. Explain the difference between overloading a method name and overriding a method name. Which of these is used with dynamic binding?
2. Explain the difference between a shallow copy and a deep copy of a Java object in your own words. Describe, giving examples, the techniques available in Java to make a deep copy of an object.
Q1.
We realize that methods are common for a set of item and case variables are unmistakable for each article. Methods are allocated their memory at the time of class declaration and example variables are allocated their memory at the time of item creation. In JAVA programming language objects are allocated their memory at the time of execution utilizing the new operator. After distribution of memory the occurrence variables are ties with their related methods at the time of execution. This type of data binding is likewise called dynamic binding or late binding or execution time binding or run time binding.
In JAVA item can not distribute their memory statically at the time of aggregation. They distribute their memory at the time of execution. So just dynamic binding is available in JAVA. The idea of static binding is mostly actualized utilizing the idea of static variables and static function. Which are apportion their memory at the time of aggregation and can be executed without object. The idea of dynamic binding is available in JAVA because of JAVA upholds disseminated handling. In disseminated handling a huge program can be deteriorated to its more modest segments and appropriated among all the processors which are associated with the worker or principle PC.
Overloading versus Overriding in Java
Overloading occurs at compile-time while Overriding occurs at runtime: The binding of overloaded technique call to its definition has occurs at compile-time anyway binding of abrogated strategy call to its definition occurs at runtime.
Static methods can be overloaded which implies a class can have more than one static technique for same name. Static methods can't be abrogated, regardless of whether you proclaim an equivalent static technique in child class it has nothing to do with a similar strategy for parent class.
The most fundamental contrast is that overloading is being done in a similar class while for overriding base and child classes are required. Overriding is tied in with giving a particular usage to the acquired strategy for parent class.
Static binding is being utilized for overloaded methods and dynamic binding is being utilized for abrogated/overriding methods.
Execution: Overloading gives better execution contrasted with overriding. The explanation is that the binding of superseded methods is being done at runtime.
private and last methods can be overloaded however they can't be abrogated. It implies a class can have more than one private/last methods of same name however a child class can't supersede the private/last methods of their base class.
Return type of technique doesn't make a difference if there should be an occurrence of strategy overloading, it tends to be same or extraordinary. Anyway in the event of technique overriding the overriding strategy can have more explicit return type .
Contention rundown should be extraordinary while doing technique overloading. Contention rundown should be same in strategy Overriding.
Technique Overriding is an ideal illustration of dynamic binding as in overriding both parent and child classes have same strategy and for this situation the type of the item figures out which strategy is to be executed. The type of article is resolved at the run time so this is known as dynamic binding.
Q2.
In shallow copy Cloned Object and unique item are not 100% disjoint.
In deep copy Cloned Object and unique item are 100% disjoint.
In shallow copy Any progressions made to cloned item will be reflected in unique article or the other way around.
In deep copy Any changes made to cloned article won't be reflected in unique item or the other way around.
In shallow copy Default rendition of clone strategy makes the shallow copy of an article.
In deep copy To make the deep copy of an item, you need to abrogate clone strategy.
Shallow copy is liked if an article has just crude fields.
Deep copy is liked if an item has references to different objects as fields.
Shallow copy is quick and furthermore less expensive. Deep copy is moderate and pricey.
You can make a deep copy with serialization without creating files.
Your object you wish to deep copy will need to implement serializable. If the class isn't final or can't be modified, extend the class and implement serializable.
Convert your class to a stream of bytes:
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(object);
oos.flush();
oos.close();
bos.close();
byte[] byteData = bos.toByteArray();
Restore your class from a stream of bytes:
ByteArrayInputStream bais = new ByteArrayInputStream(byteData);
(Object) object = (Object) new