the method without overriding will work too because it is calling Soccer class and getPlayerNumber method will be executed. i donnt understand use of @override here
The @Override annotation is for documentation purpose mostly. It allows you to avoid common mistakes. But it does not do actual overriding work. Only helps compiler to spot some common mistakes done in inheritance. Method overriding may be done without this annotation, like it always was before java 1.5. So, you should better always use @Override to get most help from compiler. There's no any sense to omit this annotation even though you can. Unless you're writing java 1.4 code. Now about that particular example. It doesn't make any sense without demonstration of the usage of those classes. Nice usage example would be like: var sports = new ArrayList<Sports>(); sports.add(new Soccer()); sports.add(new Tennis ()); sports.add(new PingPong()); sports.forEach(s -> println(s.getName()) );
Обсуждают сегодня