If i declare a abstract class without any method and a interface without any method.In this case which one is better to use in our program.
Printable View
If i declare a abstract class without any method and a interface without any method.In this case which one is better to use in our program.
Neither. Both. Either.
If you need a more informative answer, you may wish to ask a more informative question by providing context regarding the problem you're trying to solve and details of your current program. You can find more suggestions on how to ask a better question in my link below on how to ask smart questions.
Which do you think?
db
i think, we can implement more thn one interface but in case of abstract class only one class can extended.Do you have any other idea.
With so little information it's hard really to say. When you have methods, you should try to use interfaces over abstract classes(since you can implement many, and only inherit once). If you are only planning to have constants you shouldn't really use an interface. If the class is only going to have constants you may want to consider making a concrete uninstantiable class(something like Math), which has static constants and a private constructor.
Code:public class X{
private X(){
throw new IllegalAccessException("Cannot instantiate class");
}
public static final int x = ...;
//more constants as needed
}
It's a bit hard to really give concrete answers though without more information.
Thank you very much to give these information about class and interface....Can you please tell me which one is faster?
Which do you think?
db
Its not really an answerable question. Deciding whether to use an Abstract class or an Interface is completely situational. Some times you are better off using an Abstract class and other times you aren't. Programming does not accept a one size fits all solution to problems.