Beruflich Dokumente
Kultur Dokumente
Ans:
Polymorphism is the concept of “one interface and many implementations”.
Polymorphism support by java by two ways:
i) compile time or static polymorphism
ii) Runtime or Dynamic polymorphism.
Ans:
A polymorphism which achieved at the time of compilation is known as compile
time or static polymorphism.
Ans:
It is a process in which a call to an overridden method is resolved at runtime
rather than compile time.
Ans:
Constructor overloading – When more than one constructor appear with in the
single class by mismatching the argument known as Constructor overloading.
Ans:
Method overloading-When name of the method is same and appear more than
one time with a single class but by taking different argument known as Method
overloading.
Ans:
When the child and parent class method name is same as well as the argument is
known as method overriding.
Ans:
Multiple methods having same name, same return type and same argument list is
the concept of overriding.
Ans:
The following are the restriction for overriding.
i) Method only can be override but constructor cannot be.
ii) Static method cannot override.
iii) Final method cannot override.
Ans:
„this‟ keyword refer to the current class object.
10. What super keyword refers and states the use of super keyword?
Ans:
Super keyword always refers to the super class object. It can be used in 3 diff.
places in java
i) It is used to call from one to another constructor which present in two
different classes.
ii) When the data member of child class and parent class are same super
use to create a difference between them.
iii) If the method of super class and child class are same super use to
create a difference between them.
Ans:
Dynamic method dispatching is a process in which a call to an overridden method
is resolved at runtime rather than at compile time.
Ans:
Up Casting - When reference variable of parent class refers to the object of child
class, it is known as up casting.
Down Casting - When subclass type refers to the object of parent class, it is
known as down casting.
13. How many ways overloading can be possible &What are they?
Ans:
Overloading can be possible by two ways
They are
i) Method overloading
ii) Constructor overloading.
Ans:
At the time of overriding the method child class method should contains same
access specifier which present in super class method.
16. Which keyword is used to create diff. b/w super class and child class if method is
same in both classes?
Ans:
Super keyword.
Ans:
this keyword.
18. Which keyword is used to resolve conflicts between method parameter and
instance field/methods of invoked class?
Ans:
this keyword.
Ans:
i) this keyword use to differentiate between local and instance variable if
both are same.
ii) this keyword use to call the current class object without creating any
object.
iii) this keyword use to call the current object hash code.
iv) this keyword use to call from one to another constructor without allocating
any memory.
v) this keyword can be post as an argument to method.
vi) this keyword can be post as an argument to constructor.
Ans:
An overridden method is called through the reference variable of a super class
which resolved at runtime like overridden support Dynamic method dispatching.
Polymorphism manifests itself in Java in the form of multiple methods having the same
name.
In some cases, multiple methods have the same name, but different formal argument
lists (overloaded methods).
In other cases, multiple methods have the same name, same return type, and same
formal argument list (overridden methods).
22. What are the differences between method overloading and method overriding?