Core java interview Questions You'll Most Likely Be Asked (Second Edition)


Download 1.52 Mb.
Pdf ko'rish
bet11/171
Sana07.01.2023
Hajmi1.52 Mb.
#1081886
1   ...   7   8   9   10   11   12   13   14   ...   171
Bog'liq
Core JAVA Interview Questions Youll M...

public
private
protected
The keywords publicprivate and protected are access
specifiers. They specify from where the method can be accessed.
static: used to indicate that the method is a class level
method
final: used to indicate that the method cannot be overridden
abstract: used to specify that a sub–class should override
the method
native: used to specify that the method is implemented in
another language like C++
synchronized: used to indicate that the method can be
accessed by only one thread at a time
What will be the default value of a reference variable when
it is not explicitly initialized? How will you handle this in





017.
018.
a.
code?
Answer:
When a reference variable is not explicitly initialized, then its
value is null by default. If such variables are not properly
handled, they can result in a NullPointerException. So, in
order to avoid the NullPointerException, you can do one of
the following:
Ensure that variables are properly initialized
Explicitly add null checks in your code
Use Java 8 Optionals
Explain the keywords “transient” and “native”.
Answer:
The keyword transient can be used as a modifier for an instance
variable. It specifies that the JVM should ignore the variable while
serializing the containing object.
The keyword native can be used as a modifier with methods. It
specifies that the method is implemented in another language like
C, C++.
What is a comment in Java? Explain the types of
comments supported by Java.
Answer:
A comment is some text added to the code that provides
additional information about the code. It describes what the code
does to the readers of the code. Comments are ignored by the
compiler. Java supports 3 types of comments as follows:

Download 1.52 Mb.

Do'stlaringiz bilan baham:
1   ...   7   8   9   10   11   12   13   14   ...   171




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling