Java - Interview Questions and Answers for 'Abstract class' | Search Java Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com
Share

Search Java Interview Questions


 2098 questions in repository.
 There are more than 200 unanswered questions.
Click here and help us by providing the answer.
Label / Company      Label / Company / Text

   



Interview Questions and Answers for 'Abstract class' - 19 question(s) found - Order By Newest

Very Frequently asked. Have been asked in HCL Technologies very frequently ( based on 2 feedback ). Among first few questions in many interviews.
  Q1. Differences between abstract class and interface ?Core Java
Admin
info@buggybread.com
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 ).

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   classes   abstract class   interfaces     GlobalLogic  HCL Technologies  Tata Consultancy (TCS)  Infosys  Wipro  Mindtree  CapitalOne  Accenture  IBM India  Infoview Technologies  Salesforce  AT&T  United Health Group (UHG)  Verilogue  Amazon  Expeditors  Syntel  SalesForce  Cornerstone OnDemand  Expedia  OLA  NSF International  Copper Mobile  Think Future Technologies  MorphoTrust  Global Healthcare  Prodigious  Internet Brands  SciQuest  arvato Systems  iCIMS  Ideas2IT  virtusa polaris  Vitech Systems  Cognizant (CTS)      basic        frequent


 Q2. Difference between Abstract and Concrete Class ?Core Java
Anonymous
Ans. Abstract classes are only meant to be sub classed and not meant to be instantiated whereas concrete classes are meant to be instantiated.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   abstract classes   basic interview question     Goldman Sachs      basic        frequent


 Q3. What are the design considerations while making a choice between using interface and abstract class ?Core Java
Anonymous
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 :   

   Like      Discuss      Correct / Improve     java   oops   abstract classes   interfaces   advanced     ADP  AI corporation


 Q4. How is Abstraction implemented in Java ?Core Java
Admin
info@buggybread.com
Ans. Abstraction is provided in Java by following ways -

Coding to the ( Interfaces / Abstract Classes ) or contracts

By Encapsulating details within classes and exposing the minimal Door ( few public methods )

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops concepts   abstraction   interfaces   abstract class   encapsulation     Accenture  Bureau Veritas      basic        frequent


 Q5. If an Abstract class has only abstract methods, What's the difference between such a class and an interface ?Core Java2017-05-07 07:26:29

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 :   

   Like      Discuss      Correct / Improve     abstract class   interfaces     Tata Consultancy (TCS)      Basic


Very frequently asked. Usually asked in this format or as difference with interfaces / concrete classes.
  Q6. What is an abstract class ?Core Java2017-01-10 13:12:20

Ans. Abstract class is the class that is not supposed to be instantiated. The purpose of the class to only have extension to the derived class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     abstract class     Multivision  Starkey Hearing Technologies  Avaya  Tridium  LinkedIn  Acute Informatics      basic        frequent


 Q7. what will be the output ?

class Animal {
public void eat() throws Exception {
}
}

class Dog2 extends Animal {
public void eat(){}
public static void main(){
Animal an = new Dog2();
an.eat();
}
}
Core Java
Admin
info@buggybread.com
Ans. Compile Time Error: Unhandled exception type Exception

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   code   coding   overridding   late binding   exception handling   abstract class   abstract methods


 Q8. Will this code Work ? If not , Why ?

java.util.Calendar c = new java.util.Calendar();
Core Java
Admin
info@buggybread.com
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 :   

   Like      Discuss      Correct / Improve     java   date   calendar   abstract class   yes-no


 Q9. Is java.util.Date an abstract Class ? Is java.util.Calendar an abstract Class ?Core Java
Admin
info@buggybread.com
Ans. Date is not a abstract class whereas Calendar is.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   date   calendar   abstract class



Do you think these are the Best Java Frameworks ?

OpenXavaSPRING MVCApache StripesCheck everything
that is Best in Java

Click Here



 Q10. Will this code compile ?

public class BuggyBread1{
abstract public void test();
}
Core Java
Admin
info@buggybread.com
Ans. No. It will give the compilation error saying "The abstract method test in type BuggyBread1 can only be defined by an abstract class".

We need to declare the class abstract for it to have any abstract method.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   oops   abstract class   abstract methods   java compilation error


 Q11. Will this Code compile ?

abstract public class BuggyBread1{
abstract public void test(){};
}
Core Java
Admin
info@buggybread.com
Ans. No. This will give a compilation error saying "Abstract methods do not specify a body".

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     java   abstract classes   abstract methods   java compilation error   java coding   java code   coding   yes-no


 Q12. In the following code , how many methods needs to be implemented in Class B ?

public interface A{
   public void method1();
   public void method2();
   public void method3();
}

abstract class B implements A{
}
Core Java

Ans. As Class B has been declared abstract , we can either implement any of these methods and just declare rest of them abstract.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     interfaces  abstract classes  code  coding

Try 2 Question(s) Test


 Q13. What should a class do if its extending an abstract class ?Core Java

Ans. It should either implement the abstract methods or re-declare them abstract.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     abstract class     TCS  Niftek      Basic        Frequent


 Q14. When should we use Abstract classes ?Core Java2016-12-23 20:12:52

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 :   

   Like      Discuss      Correct / Improve     abstract classes     Polaris


 Q15. What was the need of creating an abstract class in Java when we cannot instantiate an object of it ?Core Java2017-04-03 09:18:49

Ans. The objective of an abstract class is to provide an interface as well as code reuse. Though we cannot instantiate an instance of abstract class but we can reuse the code by extending such a class. Moreover abstract class provides interfacing to outside components just like interfaces.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     abstract class


 Q16. Why can't we create an instance of abstract class ? Why is it restricted by compiler ?Core Java2017-04-03 13:27:57

Ans. Because Abstract class is incomplete i.e there are abstract methods that needs to be defined by extending classes.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     abstract class


 Q17. What is the importance of Abstract Class ?Core Java2017-04-30 09:37:41

Ans. Abstract classes provide a mechanism of interfacing ( using abstract method ) as well as code reuse through inheritance ( extending abstract class )

Comparing to concrete class they have an advantage of providing interface which a concrete class doesn't provide.

Comparing to interfaces they have an advantage of providing code reuse through inheritance which interfaces dont provide.

  Sample Code for abstract class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     abstract class  importance of abstract class      Basic        frequent


 Q18. What are the advantage of Abstract classes over interfaces with respect to Java 7 ? and What changed in Java 8 to help facilitate that in Java 8 ?Core Java2017-08-17 19:28:33

 This question is still unanswered. Can you please provide an answer.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like      Discuss      Correct / Improve     abstract classes  interfaces  default method      expert


 Q19. Which of the following is not true for abstract classes ?Core Java
a. Abstract Class is only meant to be sub classed and not supposed to be instantiated.
b. Abstract class handlers can be used to handle derived class objects.
c. We can't have an abstract class without abstract methods.
d. Abstract class has member elements.

Ans.c. We can't have an abstract class without abstract methods.



Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner



comments powered by Disqus
 

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked:
         

X Close this

X Close this

Help Us Improve.
Please share your
interview experience.

Company Name:   


Questions Asked: