More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know.
Ans. 1.Abstraction solves the problem at design level while encapsulation solves the problem at implementation level
2.Abstraction is used for hiding the unwanted data and giving relevant data. while Encapsulation means hiding the code and data into a single unit to protect the data from outside world.
3. Abstraction lets you focus on what the object does instead of how it does it while Encapsulation means hiding the internal details or mechanics of how an object does something.
4.For example: Outer Look of a Television, like it has a display screen and channel buttons to change channel it explains Abstraction but Inner Implementation detail of a Television how CRT and Display Screen are connect with each other using different circuits , it explains Encapsulation.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Abstract classes can have both abstract methods ( method declarations ) as well as concrete methods ( inherited to the derived classes ) whereas Interfaces can only have abstract methods ( method declarations ).
A class can extend single abstract class whereas it can implement multiple interfaces.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Car Engine is an example of encapsulation and abstraction. You ignite the car using an interface called starter and least bothered about how the tire actually moves (This is abstraction). The engine encapsulates the complete process to itself only and doesn't allow you to start the other components like the radiator etc ( this is excapsulation )
Help us improve. Please let us know the company, where you were asked this question :
Ans. Factory Pattern deals with creation of objects delegated to a separate factory class whereas Abstract Factory patterns works around a super-factory which creates other factories.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Such a class still can have member elements which can be inherited and hence facilitate code reuse. Moreover Abstract class can have non final static elements whereas interfaces are only allowed to have static final elements.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Keep it as a Abstract Class if its a "Is a" Relationsship and should do subset/all of the functionality. Keep it as Interface if its a "Should Do" relationship.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Base Class is a relative term used to signify the Parent class in Parent - Child or Base - derived relationship.
Derived Class is a relative term used to signify the Child class in Parent - Child or Base - derived relationship.
Abstract Class is a class that is not allowed to be instantiated and hence can serve only a base class for it's usage.
Concrete Class is the class which is supposed to be instantiated and hence provide definition for all implementing interface methods and extending abstract methods.
Help us improve. Please let us know the company, where you were asked this question :
Ans. No. It gives the error "Cannot Instantiate the type Calendar". Calendar is an abstract class and hence Calendar object should be instantiated using Calendar.getInstance().
Help us improve. Please let us know the company, where you were asked this question :
Ans. Abstract means that the class is only meant to be subclassed whereas final means that it cannot be subclassed so both concepts - abstract and final are actually mutually exclusive and hence not permitted together.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Abstract classes provide a mechanism of interfacing ( using abstract method ) as well as inheritance ( extending abstract class ). So they should be used in place of interfaces in case there is some code ( methods ) or object body ( member elements ) that can be reused with inheritance.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Abstract methods are the methods that need to be overridden in the derived class ( either as implementing method or again abstract method ) so it's not only allowed but its required to override abstract method in the derived class.
Help us improve. Please let us know the company, where you were asked this question :
Ans. Yes, but in that case the derived class itself should be abstract. We cannot have an object of a class without definition for the method which has been declared abstract in the parent.
Help us improve. Please let us know the company, where you were asked this question :