Which two classes correctly override the getDepth method?

Given:

class Deeper {

public Number getDepth() {

return 10;

}
}

Which two classes correctly override the getDepth method?

Given:

class Deeper {

public Number getDepth() {

return 10;

}
}

Which two classes correctly override the getDepth method?

A.
public class deep extends Deeper {
protected integer getDepth(){
return 5;
}
}

B.
public class deep extends Deeper {
public double getDepth() {
return”5″;
}
}

C.
public class deep extends Deeper {
public String getDepth () {
}
}

D.
public class deep extends Deeper {
public Long getDepth (int d) {
return 5L;
}
}

E.
public class deep extends Deeper {
public short getDepth () {
return 5;
}
}

Explanation:
Note:The abstract class Number is the superclass of classes Byte, Double, Float, Integer, Long, and Short.

Subclasses of Number must provide methods to convert the represented numeric value to byte, double, float, int, long, and short.

When class C extends B, we say that C is a”subclass”of B, and B is the”superclass”of C. This is called inheritence, because C inherited from B.



Leave a Reply 10

Your email address will not be published. Required fields are marked *


Francesco

Francesco

Here the correct answers D and E. Not A because cannot override with a method with restricted access modifier

Serg

Serg

Here have not correct answers.

A. getDepth() in deep cannot override getDepth() in Deeper attempting to assign weaker access privileges; was public

B. double is a primitive. getDepth() in deep1 cannot override getDepth() in Deeper
return type double is not compatible with Number

but Double is compatible with Number

C. String ISN’T instanceoff Number. getDepth() in deep2 cannot override getDepth() in Deeper return type String is not compatible with Number

D. isn’t the override, but Overload

E.short is a primitive. getDepth() in deep1 cannot override getDepth() in Deeper
return type short is not compatible with Number

but Short is compatible with Number

Correct:
//B.
class deep1 extends Deeper {
public Double getDepth() {
return 5d;
}
}

//E.
class deep4 extends Deeper {
public Short getDepth () {
return 5;
}
}

Eloi

Eloi

Serg you are right

gelete

gelete

B. return “5” ????

in later reviews it’s

return 5d