This is the 26th day of my participation in the August More Text Challenge
Difficulty level: Easy
The program
Program a
1) What is the output of the following program?
public class Test
{
public int getData(a) //getdata 1
{
return 0;
}
public long getData(a) //getdata 2
{
return 1;
}
public static void main(String[] args)
{
Test obj = newTest(); System.out.println(obj.getData()); }}Copy the code
A) 1 B) 0 C) runtime error D) compile error
Click here to jump to the answer
Program 2
2) What is the output of the following program?
public class Test
{
public int getData(String temp) throws IOException
{
return 0;
}
public int getData(String temp) throws Exception
{
return 1;
}
public static void main(String[] args)
{
Test obj = new Test();
System.out.println(obj.getData("HY")); }}Copy the code
A) 0 B) 1 C) compile error D) runtime error
Click here to jump to the answer
Application of three
3) What is the output of the following program?
public class Test
{
private String function(a)
{
return ("HY");
}
public final static String function(int data)
{
return ("haiyong");
}
public static void main(String[] args)
{
Test obj = newTest(); System.out.println(obj.function()); }}Copy the code
A) compiler error B) runtime error C) HY d) none
Click here to jump to the answer
Application of four
4) What is the output of the following program?
public class Test
{
private String function(String temp, int data)
{
return ("HY");
}
private String function(int data, String temp)
{
return ("haiyong");
}
public static void main(String[] args)
{
Test obj = new Test();
System.out.println(obj.function(4."HY")); }}Copy the code
A) HY B) haiyong C) compiler error D) runtime error
Click here to jump to the answer
Application of five
5) What is the output of the following program?
public class Test
{
private String function(String temp, int data, int sum)
{
return ("HY");
}
private String function(String temp, int data)
{
return ("haiyong");
}
public static void main(String[] args)
{
Test obj = new Test();
System.out.println(obj.function("HY".0.20)); }}Copy the code
A) HY B) compiler C) runtime D) haiyong
Click here to jump to the answer
6) What is the output of the following program?
public class Test
{
private String function(float i, int f)
{
return ("hy");
}
private String function(double i, double f)
{
return ("HY");
}
public static void main(String[] args)
{
Test obj = new Test();
System.out.println(obj.function(1.0.20)); }}Copy the code
A) HY B) compiler error C) runtime error D) HY
Click here to jump to the answer
The second part is the output and analysis of the program
Output and parsing
Program one output
The answer:
d
Copy the code
Description:
For method overloading, methods must have different signatures. The return type of the method does not contribute to the different method signatures, so the code above gives a compilation error. Getdata 1 and getData 2 differ only in the return type and the NOT signature.
Program two output
The answer:
c
Copy the code
Description:
Methods that throw different exceptions are not overloaded because they still have the same signature.
Program three output
The answer:
c
Copy the code
Description:
Access modifiers associated with methods do not determine the criteria for overloading. Overloaded methods can also be declared final or static without affecting the overloaded criteria.
Procedure 4 Answer
The answer
b
Copy the code
Description:
The order of arguments is an important parameter in determining method overloading. Methods are overloaded because of the order of attributes.
Procedure 5 Answer
The answer:
a
Copy the code
Description:
The order of arguments is an important parameter in determining method overloading.
Procedure 6 Answer
The answer:
a
Copy the code
Description:
This is really easy. Different types of parameters can lead to method overloading because the signature of a method changes with different types of attributes. Any method that matches the set of arguments passed in the main function is called. In this case, the first argument passed is double, so print HY.
That’s all for this article
Related articles:
Java program Java exercises 】 【 | at the output of the first set of (analysis) the output of the Java program Java exercises 】 【 | second (analysis) the output of a Java program | Java exercises 】 【 a third (including parsing) [Java exercises] | at the output of the Java program Fourth set (including the parse) the output of a Java program | Java exercises 】 【 5 sets (including parsing) the output of the Java program Java exercises 】 【 | 6 sets (including parsing) the output of a Java program | Java exercises 】 【 7 sets (including parsing) Java Java exercises 】 【 Program’s output | 8 sets (including parsing) the output of a Java program | Java exercises 】 【 9 sets of (including the parse) the output of a Java program | Java exercises 】 【 10 sets (recycling) the output of a Java program | Java exercises 】 【 11 sets of (including parsing) The output of a Java program | Java exercises 】 【 12 sets (including parsing) the output of a Java program | Java exercises 】 【 13 sets (set) the output of a Java program | Java exercises 】 【 14 sets (constructor) [Java exercises] | at the output of the Java program 15 sets of (internal) the output of a Java program | Java exercises 】 【 16 sets (threads) the output of a Java program | Java exercises 】 【 17 sets of (including parsing) the output of a Java program | Java exercises 】 【 18 sets of Java Java exercises 】 【 (rewrite) The output of the program | 19 sets of (including parsing) the output of a Java program | Java exercises 】 【 20 sets of (inheritance) the output of a Java program | Java exercises 】 【 21 sets (cast)
I’ve been writing tech blogs for a long time and this is one of my tech posts/tutorials. Hope you like it! Here is a summary of all my original and works of source: GitHub, and this is my recently just built blog: Haiyong. Site, there is no content, put some HTML games, interested can try, source code can be their own F12 copy, or directly find me to.
If you really learn something new from this article, like it, bookmark it and share it with your friends. 🤗 and finally, don’t forget ❤ or 📑.