Let's learn java programming language with easy steps

Monday, 2 October 2017

Interview Questions on Method Overloading in Java

Java Method Overloading Interview Questions

Interview Questions on Method Overloading in Java

Here we will discuss some interview questions on method overloading in java. In this post, we will see most frequently asked method overloading questions in core java interviews.

Let's start with method overloading interview questions and answers.


(1) What is method overloading in java?

If we have more than one method or multiple methods in the same class with same name but different number of arguments is known as method overloading in java.

Syntax:

class Demo
{
void show(int a, int b)//with two arguments
{}
void show(int a, int b, int c)//with three arguments
{}
psvm(){}}


(2) Why we use method overloading?

Java method overloading increases the readability of a program.

(3) How many ways we can achieve method overloading?

There are two ways we can achieve method overloading in java which is given below.

  1. By changing number of arguments.
  2. By changing the data types.

(4) Can we overload main() method in java?

Yes, We can easily overload main() method in java.




(5) What are the others name for java method overloading?

There are many other names of method overloading and these are

  • compile-time polymorphism.
  • static polymorphism.
  • static binding

Method overloading is also know as compile-time polymorphism, static polymorphism, and static binding.



(6) Can overloaded method be override?

Yes, we can easily override a overloaded method in sub-clas which is overloaded in super class.


(7) Can we overload a static method?

Yes, we can overload static methods but we cannot override static method.


(8) Can we overload constructor in java?

Yes, we can overload constructor in java.

(9) Can we declare overloaded method as final?

Yes, we can declare overloaded method as final.

(10) Can we make overloaded method synchornized?

Yes, It is possible overloaded method can be synchronized.


(11) Can we declare one overloaded method as static and another one as non-static?

Yes, we can define one overloaded method as static and another non-static in java.

class OverloadS
{
static void show(int i, int j)
{
System.out.println(i+j);
}
void show(int i, int j, int k)
{
System.out.println(i+j+k);
}
public static void main(String args[])
{
OverloadS os = new OverloadS();
os.show(10,20);
os.show(10,20,30);
}
}

Output: 30
              60

(12) Can we achieve method overloading by changing the return -type?

No, we cannot achieve method overloading by changing the return type.

(13) Difference Between method overloading and method overriding?

There are many differences between method overloading and method overriding in java and some of them are given below.

Method Overloading
  • Whenever we have more than one method with the same name but different number of arguments or different data types in the same class is known as method overloading.
  • Method overloading are happens at compile-time.
  • Method overloading are known as compile-time or static polymorphism and early binding also.

Method Overriding
  • Whenever we have super class method and sub class method are same name and same number of arguments is known as method overriding.
  • Method overriding are happens at run-time.
  • Method overriding are known as run-time or dynamic polymorphism and late binding also.

Read More :


Above all the interview questions on method overloading in java are quite useful.

Share:

1 comment:

  1. NayHoh,


    Great info! I recently came across your blog and have been reading along.
    I thought I would leave my first comment. I don’t know what to say except that I have


    . Hello,I want to add an authentication i.e login using email and password for users.I don't know how to do it using session and entity bean. Although I am able to insert data in database using session and entity bean and servlet.

    I am using glassfish server and connection pooling.

    Here is the login page(login.jsp)




    Anyways great write up, your efforts are
    much
    appreciated.


    Obrigado,

    ReplyDelete

Facebook Page Likes

Follow javatutorial95 on Google+

Follow javatutorial95 on twitter

Popular Posts

Get Updates By Email

Link

Translate