• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

can interface have abstract methods

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interfaces are meant to provide just declarations of methods that are implicitly abstract, but the interface LayoutManager has abstract method like minimumLayoutSize()
help me out
priya
 
Desperado
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An <CODE>interface</CODE> only has <CODE>abstract</CODE> methods, by definition.
 
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Methods in an interface are implicitly abstract.
An explicit "abstract" qualifier is redundant and
has no effect on compilation.
abstract interface is same as interface.
interface with explicitly declared abstract methods need not be declared abstract( for abstract classes, this is not true ).
HTH
Ajith

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ajith,
i was just browsing through the servlet API and found that servlet interface is declared as "public abstract interface Servlet" .
can anyone tell me what u mean when u declare an interface as public abstract interface , as interfaces are implicitly abstract and hence have no need to be explicitly stated as such.
thanks in advance Ajith & others,
Mahalakshmi Addanki

Originally posted by Ajith Kallambella:
Methods in an interface are implicitly abstract.
An explicit "abstract" qualifier is redundant and
has no effect on compilation.
[b]abstract interface is same as interface.

interface with explicitly declared abstract methods need not be declared abstract( for abstract classes, this is not true ).
HTH
Ajith
[/B]


 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just find something in the java bible, jls, which we can rely on, is says:
9.1.1.1 abstract Interfaces
Every interface is implicitly abstract. This modifier is obsolete and should not be used in new programs.
rong chen
 
MahaAdd
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rong..

Originally posted by Rong Chen:
just find something in the java bible, jls, which we can rely on, is says:
9.1.1.1 abstract Interfaces
Every interface is implicitly abstract. This modifier is obsolete and should not be used in new programs.
rong chen


 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
True,,, interfaces provide just the declarations of method and implicitly these methods are "public abstract".
Interfaces are useful when some classes implements it, or some other interfaces extends it.
The interface "LayoutManager" is implemented by classes like FlowLayout, GridLayout etc.
BorderLayout, CardLayout classes implements LayoutManager2.
LayoutManager2 extends LayoutManager.
So BorderLayout, CardLayout classes implements LayoutManager, but not directly.
I dun know whether i answered ur question the way u wanted !!.

[This message has been edited by Jon Aryan (edited October 06, 2000).]
 
MahaAdd
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jon Aryan,
thanks for the example.
I just wanted to know whether abstract keyword has any significance when added to an interface? if so, what?
thanks again

Originally posted by Jon Aryan:
True,,, interfaces provide just the declarations of method and implicitly these methods are "public abstract".
Interfaces are useful when some classes implements it, or some other interfaces extends it.
The interface "LayoutManager" is implemented by classes like FlowLayout, GridLayout etc.
BorderLayout, CardLayout classes implements LayoutManager2.
LayoutManager2 extends LayoutManager.
So BorderLayout, CardLayout classes implements LayoutManager, but not directly.
I dun know whether i answered ur question the way u wanted !!.

[This message has been edited by Jon Aryan (edited October 06, 2000).]


 
Jon Aryan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Maha,
Answer is "NO", except for clarity. Methods in an interface is
"public abstract" by default.
Some code.
------------------------------------
interface Mine {
// is as good as saying "public abstract", thats the default
// for an method in an interface
void tester();

/* Won't compile, must be "public"
private abstract void tester();
*/
/* Won't compile, must be "public"
protected abstract void tester();

*/

}
class Test1 implements Mine {

/*
// Won't compile. coz, ur implementing a method of an
// interface with a
// weaker access privilege ( default access in this case),
// Mr. compiler donot like this
void tester() {
System.out.println("Oops !!");
}
*/

public void tester() {
System.out.println("Mmmm... good enough !!");
}
}


----------------------------------------------------

Check out this code.
It won't compile, coz, class B is overriding the method with a weaker access privilege ( again, default access in this case),

class A {
public void tester() {
}
}

class B extends A{

void tester() {
}
}

----------------------------------------------------

It helped Maha ???
----------------------------------------------------

Originally posted by MahaAdd:
Hi Jon Aryan,
thanks for the example.
I just wanted to know whether abstract keyword has any significance when added to an interface? if so, what?
thanks again



[This message has been edited by Jon Aryan (edited October 07, 2000).]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!