aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes abstract classes vs interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "abstract classes vs interfaces" Watch "abstract classes vs interfaces" New topic
Author

abstract classes vs interfaces

sun par
Ranch Hand

Joined: Oct 03, 2002
Posts: 257
interface methods can be only be public and abstract... and interface variables can be only public, static and final or with no modifier and a value must be assigned to each variable in interface...
Abstract class does not have any restriction in method modifiers, except that abstract and final cannot occur together, abstract and native cannot occur together..Abstract method cannot be static?
Is the above statement correct?
What are the legal modifiers for abstract method?
Thanks.
[ March 27, 2003: Message edited by: sun par ]
[ March 27, 2003: Message edited by: sun par ]

Sunita<br />SCJP 1.4
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Originally posted by sun par:
...except that abstract and final cannot occur together, abstract and native cannot occur together..Abstract method cannot be static?
Is the above statement correct?

The following modifiers can not be applied to an abstract method: private, static, final, native, strictfp, or synchronized.
A private method can not be overridden so it makes no sense to declare a method that is both private and abstract.
A static method can be hidden but a static method can not be overridden. It makes no sense to declare a method that is both abstract and can not be overridden.
A final method can not be overridden so it makes no sense to have a final abstract method.
The abstract modifier specifies that a particular method will be implemented by a subclass. The native modifier specifies that the method might not ever be implemented in Java. The two requirements are not compatible so the modifiers are not compatible.
Both strictfp and synchronized specify implementation details that are not enforced on overriding methods. Therefore, it makes no sense to declare a method to be both abstract and strictfp or synchronized.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
sun par
Ranch Hand

Joined: Oct 03, 2002
Posts: 257
Thanks Dan
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Don't forget to check out the Java Language Specification (8.4.3.1 abstract methods).


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: abstract classes vs interfaces
 
Similar Threads
Question from http://www.danchisholm.net
why is an interface's varable static, and a method not allowed to be static?
NX: Bodgitt and Scarper and design/synchronization questions
remembering access modifiers
Inner classes