Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interface and abstract

 
Golam Newaz
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am little bit confused about interface and abstract.
I found this question in onesite.
8) What is the difference between interface and an abstract class?
Ans : All the methods declared inside an Interface are abstract. Where as abstract class must have at least one abstract method and others may be concrete or abstract.
*I checked WindowListener interface in java API, but i didn't
get any abstract method. I think abstract keyword should be
written before the method.
Can anyone clarify that,

 
Val Dra
Ranch Hand
Posts: 439
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
methods in an interface are implicitly abstract therefore you have to implement them in your class. Inteface is also itself implicitly abstract.
 
Sivalingam Sivasuthan
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Golam Newaz:
You are right the answer is not fully correct.
It Should be like this
Ans :
All the methods declared inside an Interface are abstract.(true)
- you can't have non abstract methods
Where as abstract class must have at least one abstract method and others may be concrete or abstract (No).
-It is not a must to have an abstract method in a Abstract Class.
Siva
 
Golam Newaz
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Val and siva, both of you are correct. But my question came in different way. I want to know why abstract modifier is dropped out of interface and of methods. After reviewing your reply, i
checked java.sun.com and found the following which actually
i was looking for.
1. abstract interfaces:
- Every interface is implicitly abstract. This abstract modifier is obsolete and should not be used in new programs.
2. abstract methods of the body of abstract interface:
For compatibility with older versions of the Java platform, it is permitted but discouraged, as a matter of style, to redundantly specify the abstract modifier for methods declared in interfaces.
It is permitted, but strongly discouraged as a matter of style, to redundantly specify the public modifier for interface methods.
Am i right.
- Golam Newaz
------------------
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic