Java
import java.io.*;public class MyCar extends Vehicle { int speed = 0; int year = 1960; int price = 0;} public class Main { public static void main(String[] args) throws Exception { // Your code here! System.out.println("my car!"); } int getP() { return price; } int getY() throws NullPointerException { return year; } int getS() throws IOexception { return speed; }}class Vehicle { int getP() throws IOexception { return 5000; } int getY() { return 1990; } int getS() { return 40; }}
こちらのコードで、getP()、getY()メソッドのオーバーライドは問題なく、
スーパークラスのgetS()メソッドは、throwsを指定していませんが、
サブクラス側でchecked例外であるIOexceptionを指定しているため、
コンパイルエラーとの事で、つまりどういう事なのか掻い摘んで教えて下さる
方がいらしたら、ぜひご教授願いたいですm(_ _)m
0 コメント