• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Abstract and Final

 
Ranch Hand
Posts: 318
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 3141
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic