Method Overloading and Overriding Flashcards

1
Q

What is the other name of Method

Overloading?

A

Method Overloading is also known as Static Polymorphism

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What kinds of argument variations are allowed in Method Overloading?

A
Method Overloading allows two methods with same name to differ
in:
1. Number of parameters
2. Data type of parameters
3. Sequence of data type of parameters
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

. Is it allowed to overload main()

method in Java?

A

Yes, Java allows users to create many methods with same name ‘main’. But only public static void main(String[] args) method is used for execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why Java does not allow overriding a static method?

A

To override a method, you need an instance of a class. Static method is not associated with any instance of the class. So the concept of
overriding does not apply here.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the other name for method overriding?

A

Runtime Polymorphism

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the difference between method overloading and method overriding in Java?

A

Method overloading occurs within the same class. Method overriding happens in two classes with hierarchy relationship.

Parameters must be different in method overloading. Parameters must be same in method overriding.

Method overloading is a compile time concept. Method overriding is a runtime concept.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is virtual function?

A

A virtual function or virtual method in an OOP language is a function or method used to override the behavior of the function in an inherited class with the same signature to achieve the polymorphism

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is meant by covariant return

type in Java?

A
Let say class B is child of class A. There is a get() method in classA as well as class B. get() method of class A can return an instance
of A, and get() method of class B return an instance of B. Here class B overrides get() method, but the return type is different.
Before Java 5, any method that overrides the method of parent class would have same return type.

From Java 5 onwards, a child class can override a method of parent class and the child class method can return an object that is child of object return by parent class method.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly