1)What is the difference between two static variable below code.
Class A{
public static final String X = "XYZ";
}
interface A{
String X = "XYZ";
}
2)if both static are variable declaration are same then which one is the efficent.
ie
Class A{
public static final String X = "XYZ";
void print(){
System.Out.Println(X);
}
}
OR
interface B {
String X = "XYZ";
}
Class A implements B{
void print(){
System.Out.Println(X);
}
}
1) Both the constants have same meaning. By default the fields declared in interface are
public static final.2) Fields in interface should not be preferred. (until unless you are very much confident that another interface won’t have field with same name).
3) Efficiency won’t be affected by where you place constant; in class or in interface.