Abstract class's can have a constructor, but you cannot access it through the object, since you cannot instantiate abstract class. To access the constructor create a sub class and extend the abstract class which is having the constructor. Example public class Test extends AbstractExample{ If interface & abstract class have same methods and those methods contain no implementation, which one would you prefer? Obviously one should ideally go for an interface, as we can only extend one class. Implementing an interface for a class is very much effective rather than extending an abstract class because we can extend some other useful class for this subclass
public abstract class AbstractExample {
public AbstractExample(){
System.out.println("In AbstractExample()");
}
}
public static void main(String args[]){
Test obj=new Test();
}
}
Click Here to See Answer .....
Subscribe to my RSS feed and get more JAVA Question, and Guideline, Plus a lot more great advice to help your Software Career.
0 comments:
Post a Comment