Core Java Interview Questions and Answers: Question 111 to Question 130
Here you can find the 100+ most frequently asked important core java interview questions and answers (111 to 130) for placement (campus) interview and competitive examinations.
111. Can a method be overloaded based on different return type but same argument type ?
Answer: No, because the methods can be called without using their return type in which case there is ambiguity for the compiler.
112. What happens to a static variable that is defined within a method of a class ?
Answer: Can’t do it. You’ll get a compilation error.
113. How many static initializers can you have?
Answer: As many as you want, but the static initializers and class variable initializers are executed in textual order and may not refer to class variables declared in the class whose declarations appear textually after the use, even though these class variables are in scope.
114. What is the difference between method overriding and overloading?
Answer: Overriding is a method with the same name and arguments as in a parent, whereas overloading is the same method name but different arguments
115. What is constructor chaining and how is it achieved in Java?
Answer: A child object constructor always first needs to construct its parent (which in turn calls its parent constructor.). In Java, it is done via an implicit call to the no-args constructor as the first statement.
116. What is the difference between the Boolean & operator and the && operator?
Answer: If an expression involving the Boolean & operator is evaluated, both operands are evaluated. Then the & operator is applied to the operand. When an expression involving the && operator is evaluated, the first operand is evaluated. If the first operand returns a value of true then the second operand is evaluated. The && operator is then applied to the first and second operands. If the first operand evaluates to false, the evaluation of the second operand is skipped.
117. Which Java operator is right-associative?
Answer: The = operator is right associative.
118. Can a double value be cast to a byte?
Answer: Yes, a double value can be cast to a byte.
119. What is the difference between a break statement and a continue statement?
Answer: A break statement results in the termination of the statement to which it applies (switch, for, do, or while). A continue statement is used to end the current loop iteration and return control to the loop statement.
120. Can a for statement loop indefinitely?
Answer: Yes, a for statement can loop indefinitely. For example, consider the following: for(;;);
121. To what value is a variable of the String type automatically initialized?
Answer: The default value of an String type is null.
122. What is the difference between a field variable and a local variable?
Answer: A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.
123. How are this() and super() used with constructors?
Answer: this() is used to invoke a constructor of the same class. super() is used to invoke a superclass constructor.
124. What does it mean that a class or member is final?
Answer: A final class cannot be inherited. A final method cannot be overridden in a subclass. A final field cannot be changed after it’s initialized, and it must include an initializer statement where it’s declared.
125. What does it mean that a method or class is abstract?
Answer: An abstract class cannot be instantiated. Abstract methods may only be included in abstract classes. However, an abstract class is not required to have any abstract methods, though most of them do. Each subclass of an abstract class must override the abstract methods of its superclasses or it also should be declared abstract.
126. What is a transient variable?
Answer: Transient variable is a variable that may not be serialized.
127. How does Java handle integer overflows and underflows?
Answer: It uses those low order bytes of the result that can fit into the size of the type allowed by the operation.
128. What is the difference between the >> and >>> operators?
Answer: The >> operator carries the sign bit when shifting right. The >>> zero-fills bits that have been shifted out.
129. Is sizeof a keyword?
Answer: The sizeof operator is not a keyword.
Here you can find the 100+ frequently asked important Core Java Interview Questions and Answers 111 to 130. If you like the material share it with your friends. Like the Facebook page for regular updates and YouTube channel for video tutorials.