Pay attention! You’re not taking the blame!
Q: Can a method have multiple variable-length arguments in Java?
A: A method can have only one variable length argument, and that variable length argument must be the last parameter of the method. Java does not allow a method to have multiple variable length arguments or variable length arguments that are not the last position of the method.
Q: Find out what is wrong with the following program and only allow modifications to call the relevant code to fix it?
public class Demo {
public void print(String str. Integer. args) {}
public void print(String str. String. args) {}
}
/ / call
Demo demo = new Demo(a);
demo.print("hello");
demo.print("hello". null);
Copy the code
[bug Mc-108966] – variable length method calls can be made with null values or null values. [bug Mc-108966] – variable length method calls can be made with null values or null values.
Demo demo = new Demo(a);
String[] strs = null;
demo.print("hello". strs);
Copy the code
Q: Is there a problem with the following program comment lines, and why?
class Base {
void print(String. args) {
System.out.println("Base print.");
}
}
class Sub extends Base {
@Override
void print(String[] args) {
System.out.println("Sub print.");
}
}
Base base = new Sub(a);
base.print("hello"); / / 1
Sub sub = new Sub(a);
sub.print("hello"); / / 2
Copy the code
A: Comment 1 will compile and print as Sub print. Because the base object transforms the subclass Sub up, the parameter list is determined by the parent class, so it will pass.
Note 2: The String type passed by the subclass does not match the String[] type required by the method. The compiler sees that the subclass overwrites the print method of the parent class. Although the argument list does not match, it does not match the parent class (because it does not match the parent class), so there is a type mismatch compilation error.
Print (Base) {print (args) {print (Base) {print (args) {print (Base) {print (Base) {print (Base) {print (Base) {print (Base) {print (Base); So it’s natural to Override, not Override, so there’s no problem with @override.
Master, don’t be too short, long you certainly won’t finish reading, so this is code farmers daily question purpose ~
After watching the sharing wave, it will be more interesting to discuss with your friends
Relax with a joke
Today noon before having a meal washroom, just saw the boss come out from inside, conveniently ask: “did you eat?”
Boss hey hey smile, did not answer.
I suddenly realized I had said the wrong thing.
Then go to the canteen to eat, the boss is also in the queue for rice, in order to make up for the fault, I bravely take the initiative to say hello: “haven’t eaten ah, thought you had eaten it.”
Take each man’s censure, but reserve your judgment.
Listen to the opinions of others, but reserve your own judgment.