1. Difference between Inheritance and Composition in Java OOPS ?
Answer:-
2. Can you overload static method in Java ?
Answer:- Yes
3. Can we declare an overloaded method as static and another one as non static in java ?
Answer:- No with same argument, but Yes with different aggument.
public class StaticAndNonStaticMethod {
private static void methodOne(String name) {
System.out.println("methodOne");
}
// static method overload
private static void methodOne(String name, String lname) {
System.out.println("methodOne");
}
// Compiler give error here :- Duplicate method methodOne(String) in type
// StaticAndNonStaticMethod
private void methodOne(String name) { // non-static method
System.out.println("methodOne");
}
// This is ok. with diffrent argument then static method
private void methodOne() { // non-static method
System.out.println("methodOne");
}
// This is ok. with diffrent argument then static method
private void methodOne(String name, String lname, String email) { // non-static // method
System.out.println("methodOne");
}
}
Answer:-
2. Can you overload static method in Java ?
Answer:- Yes
3. Can we declare an overloaded method as static and another one as non static in java ?
Answer:- No with same argument, but Yes with different aggument.
public class StaticAndNonStaticMethod {
private static void methodOne(String name) {
System.out.println("methodOne");
}
// static method overload
private static void methodOne(String name, String lname) {
System.out.println("methodOne");
}
// Compiler give error here :- Duplicate method methodOne(String) in type
// StaticAndNonStaticMethod
private void methodOne(String name) { // non-static method
System.out.println("methodOne");
}
// This is ok. with diffrent argument then static method
private void methodOne() { // non-static method
System.out.println("methodOne");
}
// This is ok. with diffrent argument then static method
private void methodOne(String name, String lname, String email) { // non-static // method
System.out.println("methodOne");
}
}
No comments:
Post a Comment