JAVA Interview Questions

Ques 1. Why Java is called as platform independent?

Ans. Java is called platform independent because of its byte codes which can run on any system irrespective of its underlying operating system. Any java code internally converted in to its byte code.

Ques 2. Is Java code 100% object orineted?

Ans. No it is not 100% object oriented language as it makes use of eight primitive data types like boolean, byte, char, int, float, double, long, short which are not objects

Ques 3. What is the difference between equals() method and == operator in Java?

Ans. equals() method is defined in Object class in Java and used for checking equality of two objects. “==” or equality operator in Java is a binary operator provided by Java programming language and used to compare primitives and objects.

Ques 4. What difference between heap and stack memory?

Ans. Stack memory only contains local primitive and reference variables to objects in heap space.Stack memory is used only by one thread of execution. Whenever an object is created, it’s always stored in the Heap space in heap memory.Heap memory is used by all the parts of the application

Ques 5. Why the concept of pointers are not used in Java?

Ans. Because they are unsafe and increases the complexity of the program. As, Java is known for its simplicity of code, adding the concept of pointers will be contradicting. Moreover, since JVM is responsible for implicit memory allocation, thus in order to avoid direct access to memory by the user, pointers are not introduced in Java.

Ques 6. Why Strings are immutable in Java?

Ans. String objects are immutable as String objects are generally cached in the String pool. Since String literals are usually shared between multiple clients, action from one client might affect the rest. It gives security, caching, synchronization, and performance of the application.

Ques 7. What are the advantages of packages in Java?

Ans. Packages help in avoiding name clashes They provide easier access control on the code Packages can also contain hidden classes which are not visible to the outer classes and only used within the package Creates a proper hierarchical structure which makes it easier to locate the related classes

Ques 8.  What is multiple inheritance? Is it supported by Java?

Ans. If a child class inherits the property from multiple classes is known as multiple inheritance. Java does not allow to extend multiple classes.The problem with multiple inheritance is that if multiple parent classes have the same method name, then at runtime it becomes difficult for the compiler to decide which method to execute from the child class. This problem is resolved in interface.

Ques 9. Is it possible to restrict inheritance ?

Ans. Yes, it is. You can restrict Inheritance by: a. Using the final keyword. b. Making the method final. c. Using private constructor. d. Using (//) Javadoc comment.

Ques 10. what is use of this keyword?

Ans. In a constructor if I have declared local variable as well as instance variable with same name then this keyword is been used.

Post Question Details

Ques. y4ox23

Posted On:9/21/2022 7:04:06 PM

Ques. test1

Posted On:5/2/2020 9:03:54 PM

Ques. tfgukhukhkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkksettttttttttttttttttdt ujgyuihk ihjok;l

Posted On:3/4/2020 11:20:12 PM