Recall & Review
beginner
What is method calling in Java?
Method calling is the process of executing a method by using its name followed by parentheses, optionally passing arguments inside the parentheses.
touch_appClick to reveal answer
beginner
How do you call a method named
greet with no parameters in Java?You call it by writing
greet(); inside another method or block of code.touch_appClick to reveal answer
beginner
What happens if a method requires parameters but you call it without any?
The Java compiler will show an error because the method call does not match the method's parameter list.
touch_appClick to reveal answer
intermediate
Explain the difference between calling a static method and an instance method.
A static method is called using the class name, like <code>ClassName.methodName()</code>. An instance method is called on an object, like <code>objectName.methodName()</code>.touch_appClick to reveal answer
beginner
What is the output of this code?<br><pre>class Test {
static void sayHi() {
System.out.println("Hi!");
}
public static void main(String[] args) {
sayHi();
}
}</pre>The output is:
This happens because the static method
Hi!
This happens because the static method
sayHi() is called inside main without needing an object.touch_appClick to reveal answer
How do you call a method named
calculate that takes two integers as parameters?Which of these is the correct way to call a static method
printMessage in class Utils?What will happen if you call a method with the wrong number of arguments?
Which symbol is used to call a method in Java?
If you have an object
car of class Car, how do you call its method startEngine?Describe how to call a method in Java and explain the difference between calling static and instance methods.
What errors can happen if you call a method incorrectly? Give examples.
