Java Magazine, July/August 2018
ORACLE COM JAVAMAGAZINE JULY AUGUST 2018 85 fix this vides behavior for exactly one method Further that method must be one abstract method of the interface that is being implemented As a result its clear that anonymous classes still have a purpose in the language even with the advent of the lambda syntax In the sample syntax the construction is performed using zero arguments That mandates that the parent class BaseClass in the sample must have a zero argument constructor it could also have other constructors However in the more general case arguments are permitted provided that they match an available constructor in the type being extended Consequently option E is incorrect Answer 4 Option A is correct This question investigates abstract classes and methods A class may be declared abstract by adding the keyword abstract before the keyword class like this public abstract class MyClass Java Language Specification section 8111 describes abstract classes There are two key consequences when a class is declared to be abstract First creating an instance of that class is prohibited Subclasses of it may be defined and provided those classes are not abstract those subclasses can be instantiated However you can never have an instance of an abstract class itself The second thing that changes is that an abstract class is permitted to declare abstract methods Concrete classes nonabstract ones if you like are prohibited from doing this And that pinpoints the problem in this question The Car class is not abstract and therefore it is prohibited from containing an abstract method As a result option A is correct and options B C D and E are incorrect If the Car class had been declared abstract how would things have been diferent Immediately the Car class would compile successfully At that point you have new considerations First is it permitted to create an instance of RacingCar Yes absolutely it is RacingCar at that point would be a correct and complete concrete class A concrete class is not permitted to have any abstract methods but the accelerate method thats defined in RacingCar is a correct imple Question 4 page 78
You must have JavaScript enabled to view digital editions.