Which of the following can be inserted into Lion to make this code compile? (Choose all
that apply)
that apply)
class HasSoreThroatException extends Exception {}
class TiredException extends RuntimeException {}
interface Roar {
void roar() throws HasSoreThroatException;
}
class Lion implements Roar {
// INSERT CODE HERE
}
A. public void roar(){}
B. public void roar() throws Exception{}
C. public void roar() throws HasSoreThroatException{}
D. public void roar() throws IllegalArgumentException{}
E. public void roar() throws TiredException{}
class TiredException extends RuntimeException {}
interface Roar {
void roar() throws HasSoreThroatException;
}
class Lion implements Roar {
// INSERT CODE HERE
}
A. public void roar(){}
B. public void roar() throws Exception{}
C. public void roar() throws HasSoreThroatException{}
D. public void roar() throws IllegalArgumentException{}
E. public void roar() throws TiredException{}
Explain:
Mehod implement/overriden olunan zaman compiler method-un exceptions list-nə baxır.Əgər checked exception varsa overridden olunan methodda ya həmin exception və ya subclass ı qeyd olunmalıdı ya da heç bir exception qeyd olunmamalıdı method exceptions listdə.Əks halda compiler error verəcək.RuntimeException unckecked exception tipi olduğu üçün compiler görmür onu.Ona görə bu zaman normal compile olunur. Cavab ACDE
Comments
Post a Comment