Q 1) What is the main objective of garbage collection?
Ans: The main objective of this process is to free up the memory space occupied by the
unnecessary and unreachable objects during the Java program execution by deleting
those unreachable objects. This ensures that the memory resource is used efficiently, but it provides no
guarantee that there would be sufficient memory for the program execution.
Q2) Can the static methods be overridden?
Ans: No! In a subclass, static methods with the same signature can be declared, but run-time polymorphism is not possible in these circumstances.
While dynamic polymorphism or overriding take place at runtime, static methods are loaded and searched up statically at build time. Therefore, these approaches cannot be changed.
Q3 ) When can you use super keyword?
Ans: 1) The super keyword is used to access hidden fields and overridden methods or
attributes of the parent class.
Following are the cases when this keyword can be used:
–> Accessing data members of parent class when the member names of the class and its child subclasses are same.
–>To call the default and parameterized constructor of the parent class inside
the child class.
–>Accessing the parent class methods when the child classes have overridden
them.
Q4)What is a classloader?
Ans:) The Classloader component of the (JRE)Java Runtime Environment is in charge of dynamically loading Java classes and interfaces into the Java Virtual Machine (JVM) while bytecode or generated dot-class files are being executed. Classloaders eliminate the requirement for the Java run-time system to be aware of files and file systems.
Q5) What is Java string Pool?
Ans:)All of the strings defined in the java programme are kept in a heap memory location called a Java String Pool. The stack contains a distinct location for the variable for storing the string. When a new string object is created, the JVM first checks the String pool to see if the object already exists. If it does, the object reference is shared with the variable; otherwise, a new object is created.
Q6) What will happen if we don’t declare main method as static?
Ans 🙂 If we do not declare main method as static then program will run, but our main method will not be treated as entry point of program.
Related Posts:
- Comparison Between Java And Python Programming Languages.
- Java Spring MVC (Model View Controller) - Model Attribute
- Exception Handling In Java
- Multi-Threading in Java
- Generics In Java
- Set Interface in Java
- List in Java
- Java Spring Boot Project
- Java Interview Questions (Part 1)
- Java Annotations
- Java Viva Questions (Part 1)
- Get List of all Countries its States and Cities Using API
- Install CURL in AWS Ubuntu
- ISO Alpha-2, Alpha-3, and Numeric Country Codes.