This section contains collection of frequently asked questions(faqs) in interview or viva of Java.
Q. What is the difference between Interface and abstract class ?
|An abstract class can have implementation of some of its method with some abstract method. Abstract method declares with abstract keyword.||All of the method in an interface is abstract. You don't need to put abstract keyword in front of every method.|
|The field declare in Abstract class can have any type private, public extra.||The field declared in Interface must be static and final.|
|It can have constructors.||It can't have constructors.|
|A class can't extends interface, it implements interface.||An interface can extend another interface|
|A class can extend only one abstract class.||A class can implements several interface.|
|The subclass of an abstract class must implements all of the abstract methods in the super class. But need to implement no abstract methods.||A class implementing an interface has to implements all the methods of the interface.|
Q. What is synchronization in multithreading ?
Ans: In multithreading, synchronization is the mechanism to control the access of multiple threads to shared resources. Without access control using synchronization, it is possible that one thread modify the resource which is used by another thread , at the same time, for modification. This could lead to serious error.
Q. What is static in Java ?
Ans: Static means one per class regardless of how many instances it have. This means you can use static elements without instantiating the class. You can use Static method of a super class into a static method of its subclass unless method is not declared final. It means you can't use a static method within a nonstatic method.
Q. What is final ?
Ans : If a class is final, it can't be extended means it can' t be sub classed. If a method is final, it can' t be override. If a variable is final, you can't alter it.
Q. What are the different states of thread ?
Ans : Following are the different states of thread :
Q. Difference between HashMap and Map ?
Ans : Map is the Interface and HashMap is the class that implements it.
Q. Difference between Vector and ArrayList?
Ans : ArrayList is not synchronized while Vector is synchronized.
Q. What are different types of inner classes?
Ans. Following are the type of inner classes :
Recommend the tutorial