Can we overload the
static method in Java?
Yes,
you can overload a static method in Java. You can declare as many static
methods of the same name as you wish provided all of them have different method
signatures.
public class Test {
|
public static void Show(int i)
{
|
System.out.println("i : " +
i);
|
}
|
public static void Show(int i, int j) {
|
System.out.println("i : " +
i + "
and j : " + j);
|
}
|
public static void main(String args[]) {
|
Show(10);
|
Show(10,
20);
|
}
|
}
|
i: 10
i: 10 and j: 20
Can we override the final method in Java?
No, you cannot override a final method in Java; final keyword with the method is to prevent method overriding. You use final when you don't want subclass changing the logic of your method by overriding it due to security reason. This is why the String class is final in Java. This concept is also used in the template design pattern where the template method is made final to prevent overriding.
No, you cannot override a final method in Java; final keyword with the method is to prevent method overriding. You use final when you don't want subclass changing the logic of your method by overriding it due to security reason. This is why the String class is final in Java. This concept is also used in the template design pattern where the template method is made final to prevent overriding.
No comments:
Post a Comment