interface and abstract

Golam Newaz

Ranch Hand

Posts: 64

posted 15 years ago

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

posted 15 years ago

methods in an interface are implicitly abstract therefore you have to implement them in your class. Inteface is also itself implicitly abstract.

Val SCJP <BR>going for SCJD

Sivalingam Sivasuthan

Ranch Hand

Posts: 75

posted 15 years ago

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

- Siva<br /> Sun Certified Programmer for the Java™2 Platform

Golam Newaz

Ranch Hand

Posts: 64

posted 15 years ago

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 ------------------