Basic Java Interview Question and Answers

29. What is the difference between abstract class and interface?
 
  • All the methods declared inside an interface are abstract whereas abstract class must have at least one abstract method and others may be concrete or abstract.
  • In abstract class, keyword abstract must be used for the methods whereas interface we need not use that keyword for the methods.
  • Abstract class must have subclasses whereas interface can’t have subclasses.
 
Your Name Your Email-ID
Your Answer
30. What is shadowing?
  Declaring the same variables of parent class in the subclass is known as shadowing.
 
Your Name Your Email-ID
Your Answer
31. What is the use of bin and lib in JDK?
  Bin contains all tools such as javac, appletviewer, awt tool etc. whereas lib contains API and all packages.
 
Your Name Your Email-ID
Your Answer
32. What is interface?
  Interface is similar to a class which may contain method's signature only but not bodies and it is a formal set of method and constant declarations that must be defined by the class that implements it. Interfaces are useful for:
  • Declaring methods that one or more classes are expected to implement.
  • Capturing similarities between unrelated classes without forcing a class relationship.
  • Determining an object's programming interface without revealing the actual body of the class.
 
Your Name Your Email-ID
Your Answer