Amazon Interview Question
Software Engineer / DevelopersCountry: United States
A normal class is a complete class where as abstract class is not a complete class, you can declared the contract as per the requirement in incomplete class, later you can fulfill the contract as defined. loose coupling is provided by abstract class but abstract class is not 100% abstract thats the reason Interface concept came into the picture.
I would like to answer the second part of the question regarding the usage of the abstract class Lets say class A contains methods a1 , a2 and a3. Now a1 is a method which should be implemented specific to the subclass and it has no relevance if implemented in the parent class, and methods a2 and a3 use a1.
The best real time example that uses Abstract class is the InputStream class, here the read method is overloaded and all the overloaded methods depend on the one abstract read method, which is implemented by the specific child classes like FileInputStream , ZipFileInputStream
1. Abstract classes cannot not be instantiated.
- mageshkhanna March 19, 20122. Abstract classes can be used to represent generic types like Animal
3. Abstract class can be extended by a concrete class in such a case, it must implement all the abstract methods of the abstract class that it is extending, if not, then it this class must be marked as abstract.
4. Abstract class can have abstract as well as non abstract methods.