0% found this document useful (0 votes)
60 views3 pages

Java Viva Top 30 Questions

Uploaded by

kashifkaif18th
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views3 pages

Java Viva Top 30 Questions

Uploaded by

kashifkaif18th
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Top 30 Mostly Asked Java Viva

Questions with Answers


1. 1. What is Java?

Answer: Java is a high-level, object-oriented, platform-independent programming language


developed by Sun Microsystems.

2. 2. What are the main features of Java?

Answer: Platform independent, Object-oriented, Secure, Robust, Portable, Multithreaded,


Automatic garbage collection.

3. 3. What is JVM, JRE, and JDK?

Answer: JVM executes Java bytecode. JRE = JVM + libraries. JDK = JRE + development tools.

4. 4. What is the difference between == and .equals()?

Answer: == compares references, .equals() compares actual values (content).

5. 5. What is inheritance?

Answer: Inheritance allows one class to inherit the properties and methods of another class
using the extends keyword.

6. 6. What is polymorphism?

Answer: Polymorphism means the same function behaves differently in different situations.
(overloading/overriding).

7. 7. What is method overloading?

Answer: Same method name with different parameter lists within the same class.

8. 8. What is method overriding?

Answer: Child class provides its own implementation of a method defined in the parent
class.

9. 9. What is the difference between abstract class and interface?

Answer: Abstract class can have abstract and concrete methods, interfaces only abstract
methods. Interfaces support multiple inheritance.

10. 10. What is a constructor?


Answer: A special method used to initialize objects. It has the same name as the class and no
return type.

11. 11. What is encapsulation?

Answer: Binding data and methods into a single unit (class) and hiding internal details
using private access modifiers.

12. 12. What is the difference between String, StringBuilder, and StringBuffer?

Answer: String is immutable, StringBuilder is mutable and not thread-safe, StringBuffer is


mutable and thread-safe.

13. 13. What are access modifiers?

Answer: Keywords to set visibility: public, private, protected, and default.

14. 14. What is the use of this keyword?

Answer: this refers to the current object of the class.

15. 15. What is the use of super keyword?

Answer: super refers to the parent class object.

16. 16. What is exception handling in Java?

Answer: Handling runtime errors using try-catch-finally blocks to prevent program


termination.

17. 17. What is the difference between throw and throws?

Answer: throw is used to throw an exception, throws declares what exception a method
might throw.

18. 18. What is multithreading?

Answer: Executing multiple threads simultaneously for better performance.

19. 19. What is the difference between ArrayList and LinkedList?

Answer: ArrayList is fast for random access, LinkedList is fast for insertion/deletion.

20. 20. What is garbage collection?

Answer: Automatic memory management where Java destroys unused objects using the
garbage collector.

21. 21. What are wrapper classes?

Answer: Classes that convert primitive types to objects (e.g., int to Integer).
22. 22. What is final keyword?

Answer: Used to make variable constant, method non-overridable, and class non-
inheritable.

23. 23. What is an interface?

Answer: An interface is a blueprint for classes. It contains only abstract methods.

24. 24. What is an abstract class?

Answer: A class that cannot be instantiated and may contain abstract methods.

25. 25. Difference between stack and heap memory?

Answer: Stack stores local variables and method calls, heap stores objects.

26. 26. Can a class have multiple constructors?

Answer: Yes, using constructor overloading.

27. 27. What is static keyword?

Answer: Used to declare class-level members shared across all objects.

28. 28. Can we overload the main method?

Answer: Yes, but JVM always calls the standard main(String[] args) method.

29. 29. Can we have a try block without a catch block?

Answer: Yes, but it must be followed by a finally block.

30. 30. Can we override a static method?

Answer: No, static methods are class-level and cannot be overridden, only hidden.

You might also like