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


Explain what happens when the following code is


Download 1.52 Mb.
Pdf ko'rish
bet47/171
Sana07.01.2023
Hajmi1.52 Mb.
#1081886
1   ...   43   44   45   46   47   48   49   50   ...   171
Bog'liq
Core JAVA Interview Questions Youll M...

Explain what happens when the following code is
compiled and executed:
package com.questions;


120.
public class CoreJava {
private String getQuestion() {
return “Question1”;
}
}
package com.questions;
class JSP extends CoreJava {
public void getJSPQuestion() {
Sytem.out.println(getQuestion());
}
}
Answer:
The above code will not compile. The class CoreJava defines a
private method getQuestion(). The getJSPQuestion()
method in the sub–class invokes this private super–class
method. Since a private method cannot be accessed by a sub–
class, a compilation error occurs.
Explain the java.lang package.
Answer:
The java.lang package has classes that are important to the
Java programming language. It includes the wrapper classes like
Byte, Boolean, Integer, Double, etc. It has classes like
String, StringBuffer and StringBuilder which are useful
for String manipulation. It has classes like Thread, Runnable
which are useful for creating multi–threaded applications. It has
Throwable and other Exception classes which are useful for
Java’s exception handling feature.



121.
122.
CHAPTER
11
Exception Handling
Explain ‘throw’, ‘throws’ and ‘Throwable’ in Java.
Answer:
The throws keyword is used to specify that a particular method
throws an unhandled exception or multiple exceptions which
need to be handled separately. It basically specifies that you do
not want to handle the error condition within the method but want
to delegate the exception handling to some other part of your
code.
The throw keyword is used inside a method to explicitly throw
an exception.
Throwable is the base class in the exception hierarchy. Custom
exceptions can be created by extending the ‘Throwable’ class.

Download 1.52 Mb.

Do'stlaringiz bilan baham:
1   ...   43   44   45   46   47   48   49   50   ...   171




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