What is an interface How is extending a class different from
What is an interface? How is extending a class different from implementing an interface?
Solution
Inteface: Interface is nothing but a class which contains abstract methods and constants only.
Abstract methods are the methods which have declaration but no bosy implementation.
Interfaces can not have constrcutor and can not be instanstiated. By using interface we can achive multiple inheritance.
Inheritance goes with \"implements\" keyword in interfaces
where as Inheritance goes with \"extends\" keyword in class.
If we implements interface in sub class then we should implement all abstract methds in interface in sub classses.
interface syntax
public interface interfacename{
public abstract void abstractMethod1();
public abstract void abstractMethod2();
public static final CONSTACT = 1000;
}
Class syntax
public class className{
public void methodA(){
}
public void methodB(){
}
}
Inheritance goes with implements in interface
public class A implements interfaceName{
}
Inheritance goes with extends in class
public class A extends ClassName{
}
Inheritance goes with implements in interface
public class A implements interfaceName{
}
