Rule: If the superclass method declares an exception, the subclass overridden method can declare the same, subclass exception or no exception but cannot declare parent exception.
The answer is A(tested)
public class Video{
public void play() throws IOException{
System.out.print("Vidoe played.");
}
}
class Game extends Video{
public void play() throws IOException{
super.play();
System.out.print("Game played.");
}
public static void main(String[] args) {
try {
new Game().play();
}catch (Exception e){
System.out.println(e.getClass());
}
}
}
Answer is B, tested
class test{
public void printValues() throws IOException {
System.out.println("Hi");
}
}
class test2 extends test{
public void printValues() throws Exception{
super.printValues();
System.out.println("hi2");
}
}
upvoted 2 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
Chiraj
Highly Voted 3 years, 5 months agosteefaand
Most Recent 5 months, 4 weeks agoiSnover
5 months, 4 weeks agoWilsonKKerll
2 years, 4 months agomevlt
2 years, 5 months agomevlt
2 years, 5 months agoSvetleto13
2 years, 12 months agojduarte
3 years, 6 months agoAbdullah_Rahahleah
3 years, 7 months ago