Virtusa – Java Interview Questions
Here is the list Java Interview Questions which are recently asked in Virtusa company. These questions are included for both Freshers and Experienced professionals.
1. Why the main method is static in java?
Java main () method is always static, so that compiler can call it without the creation of an object or before the creation of an object of the class.
2. What is “this” keyword in java?
The keyword refers to the current object in a method or constructor. The most common use of the keyword is to eliminate the confusion between class attributes and parameters with the same name.
3. What is an abstract class?
Abstract classes are classes that contain one or more abstract method which is a method that is declared, but contains no implementation. Abstract classes cannot be instantiated, and require subclasses to provide implementations for the abstract methods.
4. How abstract classes are similar or different in Java from C++?
In C++, if a class has at least one pure virtual function, then the class becomes abstract whereas in Java, a separate keyword abstract is used to make a class abstract.
5. What is object cloning?
Object cloning refers to the creation of an exact copy of an object using assignment operator and It creates a new instance of the class of the current object and initializes all its fields with exactly the contents of the corresponding fields of this object.
6. How is inheritance in C++ different from Java?
C++ supports multiple inheritance of arbitrary classes. In Java a class can derive from only one class, but a class can implement multiple interfaces. Java explicitly distinguishes between interfaces and classes.
7. Can we override private methods in Java?
No, we cannot override private or static methods in Java because private methods are not visible to any other class which limits their scope to the class in which they are declared.
Free PDF : Get our updated Java Course Content pdf
8. What is “super” keyword in java?
The super keyword is a reference variable which is used to refer immediate parent class object. Whenever the instance of subclass is created, an instance of parent class is created implicitly which is referred by super reference variable.
9. How are Java objects stored in memory?
In Java, all objects are dynamically allocated on Heap. When we only declare a variable of a class type, only a reference is created. To allocate memory to an object, we must use new (). So the object is always allocated memory on heap.
10. Differences between HashMap and HashTable in Java.
There are several differences between HashMap and Hashtable in Java: Hashtable is synchronized and better for non-threaded applications whereas HashMap is not and as unsynchronized Objects typically perform better than synchronized ones. Hashtable does not allow null keys or values.
11. What is static variable in Java?
Static variable in Java is variable which belongs to the class and initialized only once at the start of the execution. It is a variable which belongs to the class and not to object. Static variables are initialized only once, at the start of the execution.
12. How HashMap Works in Java
HashMap uses its static inner class Node
13. Design a Good Key for HashMap
The best candidate for Key in HashMap would be an Immutable Class with properly implement Equals and Hashcodemethod(Example: String Class). The better hashcode and equals method implementation is the better performance of HashMap would be.
Get Answer for all the above questions and place in your dream company
Wants to Become an ExpertKnow More
TOP MNC's JAVA INTERVIEW QUESTIONS & ANSWERS
Here we listed all Java Interview Questions and Answers which are asked in Top MNCs. Periodically we update this page with recently asked Questions, please do visit our page often and be updated in Java.