Interview Questions and Answers - Order By Newest Q101. What is the default execution method in Java? Core Java
Ans. public static void main(String[] args) Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  main method Q102. Are final methods faster than regular instance methods ? Core Java
Ans. Yes. As they cannot be overridden , there is no use of virtual table concept which is used for dynamic binding resolution. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  final methods   final keyword expert Q103. What is virtual table with respect to method overriding in Java ? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  vtable  virtual method table   method overriding  runtime polymorphism  object oriented programming (oops)  oops concepts Q104. How is the virtual method table implemented in Java? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  virtual method table   method overriding  runtime polymorphism  object oriented programming (oops)  oops concepts expert   rare Q105. How many VTables are there for each class ? Core Java
Ans. There is one VTable for each class. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  virtual table method  vtable  runtime polymorphism  object oriented programming (oops)  oops concepts   method overriding intermediate   rare Q106. Have you ever used java.util.Objects class ? Core Java
Ans. Yes, We are using requireNonNull method for validating if the object is null. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  objects  util methods   rare Q107. What is method hiding in Java ? Core Java
This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  method hiding Q108. Which Java version supports Interface Default methods ? Core Java
Ans. Java 1.8 or Java 8 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  default methods   interface default methods   java 8  java 8 features Q109. Can we call a static method using reference currently pointing to null. Core Java
Ans. yes, we can.
exa: public class Java{
public static void main(String... args) {
JAva j= null;
j.greeting(); // call with null reference
}
public static void greeting() {
System.out.println("Hello World");
}
} // output: Hello World Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  static methods   static Asked in 1 Companies Q110. How can you verify if there were interactions with a static method using PowerMock ? PowerMock
Ans. We can use PowerMockito.verifyStatic for this purpose
PowerMockito.verifyStatic(VerificationModeFactory.times(1));
<Class_Name>.<static_method_name>; Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  mocking static methods Q111. in the following class:
class A {
void methoda(Object o) {
Sysout("Object");
}
void methoda(String s) {
Sysout("String");
}
public static void main(String []args) {
A a = new A();
a.methoda(null);
}
}
what will be printed? Core Java
Ans. String Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  Code  Coding  method overloading Asked in 1 Companies Q112. Can a method return more than one value at a time in Java ? Core Java
Ans. object / native type returned can only be one but an object can comprise of a array , collection or a group of different value types. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java methods Q113. What are inline functions ? Do we have inline functions in Java ? Core Java
Ans. Inline functions , just like C++ Macros is an optimized technique used by compiler to reduce the execution time. If the function is working on pre identified values ( which aren't resolved at runtime ), the function can execute the method and evaluate the outcome at compile time only instead of making a function call at runtime.
In Java, the optimizations are usually done at the runtime or JVM level. At runtime, the JVM perform some analysis to determine which methods to inline. Java compiler would never inline any method and there is no way in java for the developer to explicitly define inlining of methods as it's take intrinsically care of during runtime only. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  inline functions  inline methodsAns. Inline functions , just like C++ Macros is an optimized technique used by compiler to reduce the execution time. If the function is working on pre identified values ( which aren't resolved at runtime ), the function can execute the method and evaluate the outcome at compile time only instead of making a function call at runtime. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  inline functions  inline methods  C++ Asked in 1 Companies Q115. why is "".equals(str); safer than str.equals("")? Core Java
Ans. str.equals("") this statement will throw NullPointerException if str is null where as "".equals(str) works fine even if str is null Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  equals method Asked in 1 Companies Q116. What is the use of defining equals , compareTo and hashcode methods in a class ? Where are they used ? Core Java
Ans. equals, compareTo and hashcode are of use when the objects are used within collections.
Equals helps with collections that helps maintaining only unique objects ( like Set )
compare and compareTo helps with collections that helps maintaining objects in order ( TreeSet, TreeMap etc )
hascode helps with collections that facilitates hash searching ( like hashSet, hashMap etc ) Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  equals   compareTo   hashcode method Q117. What is the difference between method and function in Typescript ? TypeScript
Ans. Method belongs to a class whereas function isn't. So the only difference is the scope in which they are defined. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  method vs function in typescript Q118. Which of the following is false ? Core Java
a. A Class cannot override both hashcode and equals method. b. A class can override both hashcode and equals method. c. A Class must override hashCode method if its overridding equal method. d. A Class can override hashCode even if its not overridding equals method.Ans.a. A Class cannot override both hashcode and equals method.
a. Abstract Class is only meant to be sub classed and not supposed to be instantiated. b. Abstract class handlers can be used to handle derived class objects. c. We can't have an abstract class without abstract methods. d. Abstract class has member elements. Ans.c. We can't have an abstract class without abstract methods.
Q120. Which of the following keyword is expected with main method declaration ? Core Java
a. Final b. Static c. Volatile d. TransientAns.b. Static
Q121. Which of following about main method is not true ? Core Java
a. We can have multiple methods named main in a class b. We can have var args with the main method c. We can overload main method d. We can override main methodAns.d. We can override main method
Q122. Other name for setter methods is .. Core Java
a. Getter Methods b. Redefinition Methods c. Final methods d. Mutator methodsAns.d. Mutator methods