File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Abstract and Final Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Abstract and Final" Watch "Abstract and Final" New topic
Author

Abstract and Final

Matt DeLacey
Ranch Hand

Joined: Oct 12, 2000
Posts: 318
I just came across a mock exam answer that said that
all of the methods in an interface are "implicitly static, final, and abstract." How can this be? In particular I don't understan how something can be final AND abstract. Can someone explain the reasonaing behin all 3 (static, final, and abstract). I was thinking it was final so that you couldn't extend the interfaces and that it was abstract to force you to define the methods therin if you implemented the interface. Why it is implicitly static I do not know, and how it can be abstract and final I do not know.

Matt DeLacey
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 3901
you got me i just looked up 2 interfaces in the API and all the methods were public and void is all, public void run() for example.


I never took notes in college. That's how I got a 4.0 the first 2 years, and a 3.5 the second two years.
Jane Griscti
Ranch Hand

Joined: Aug 30, 2000
Posts: 3141
Hi Matt,
The variables declared in an Interface can only be constants so they are 'static' and 'final'.
Methods are implicitly 'public' and 'abstract'.
You're right ... you can't have a 'final abstract' method ... anywhere.
Hope that helps.
------------------
Jane


Jane Griscti
SCJP, Co-author Mike Meyers' Java 2 Certification Passport
yogesh sood
Ranch Hand

Joined: Aug 31, 2000
Posts: 108
ya im agree with jane.
how can u have method abstract as well as final
when u say a method is abstract means that will be implement by subclass or class that implements interface.
and
when u say final method cannot be override.
so both are opposite so they cannot be used togather
Following are some rules will help u

It is a compile-time error for a private method to be declared abstract. It would be impossible for a subclass to implement a private abstract method, because private methods are not visible to subclasses; therefore such a method could never be used.
It is a compile-time error for a static method to be declared abstract.

It is a compile-time error to declare an abstract class type such that it is not possible to create a subclass that implements all of its abstract methods. This situation can occur if the class would have as members two abstract methods that have the same method signature but different return types.
Abstract classes have constructor.
Abstract Class can have Static method it can even have main().
Because a final class never has any subclasses, the methods of a final class are never overridden
A compile-time error occurs if a class is declared to be a subclass of itself. For example:
class Point extends ColoredPoint { int x, y; }
class ColoredPoint extends Point { int color; }
. If circularly declared classes are detected at run time, as classes are loaded then a ClassCircularityError is thrown.
u can Override method and can make it Final.
It is a compile-time error for a final method to be declared abstract.
An abstract class can override an abstract method by providing another abstract method declaration. This can provide a place to put a documentation comment , or to declare that the set of checked exceptions that can be thrown by that method, when it is implemented by its subclasses, is to be more limited.

An instance method that is not abstract can be overridden by an abstract method. For example, we can declare an abstract class Point that requires its subclasses to implement toString if they are to be complete, instantiable classes: calling Super.toString() in subclass Will be error as toString() in Point overrides that in Object.
if u have any doubt feel free to contact


If its green its biology if its stinkks its chemistry if it has numbers it is Maths and if it doesn't work its TECHNOLOGY
 
 
subject: Abstract and Final
 
Threads others viewed
Innner class in Interface
Abstract class and interface
Sierra and Bates - Interface Access Modifiers
Regarding abstract class
Kathy / Bert interface question
developer file tools