Monthly Archives: June 2024

Abstract Methods in Interfaces An interface defines a contract by specifying a set of abstract and default method declarations, but provides implementations only for the default methods—not for the abstract methods. The abstract methods in an interface are all implicitly abstract and public by virtue of their definitions. Only the modifiers abstract and public are allowed, but these are invariably omitted. An abstract method declaration has the following simple form in a top-level interface: Click here to view code image return_type method_name (formal_parameter_list)throws_clause; An abstract method declaration is essentially a method header terminated by a semicolon (;). Note that an abstract method is an instance method whose implementation will be provided by a class that implements the interface in which the abstract method is declared. The throws clause is discussed in §7.5, p. 388. The interface Playable shown below declares an abstract method play(). This method is implicitly declared to be…

Read more

1/1