Latest Update Already Passed
What is a method in Java?
✔✔ A block of code that performs a specific task and can be called multiple times.
Can a method be empty?
✔✔ Yes, it can have an empty body `{}`.
How do you prevent a method from being overridden?
✔✔ By marking it as `final`.
What happens if a method calls itself too many times?
✔✔ It results in a `StackOverflowError`.
How do you call a static method inside a non-static method?
✔✔ By using the class name or calling it directly.
1
,What is an accessor method?
✔✔ A method that retrieves values from private fields.
How do you create a method reference in Java?
✔✔ By using `ClassName::methodName` or `object::methodName`.
What happens if a method's return type does not match the actual return value?
✔✔ A compilation error occurs.
How do you pass an array to a method?
✔✔ By specifying the array type in the parameter list.
Can a method throw multiple exceptions?
✔✔ Yes, by separating exception types with commas in the `throws` clause.
What is a helper method?
✔✔ A private method used internally within a class to perform small tasks.
2
, How do you override a method in an abstract class?
✔✔ By providing an implementation in a subclass.
How do you measure the execution time of a method?
✔✔ By recording the time before and after execution using `System.nanoTime()`.
What does `@FunctionalInterface` indicate?
✔✔ That an interface contains exactly one abstract method for functional programming.
How do you enforce a method implementation in subclasses?
✔✔ By declaring it `abstract` in a superclass.
Can a method be both `static` and `final`?
✔✔ Yes, but it cannot be overridden.
How do you declare a method in Java?
✔✔ By specifying a return type, name, and parameters inside a class.
3