• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

implementing abstract method in one class in another abstract class

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Supose if have two class say class1 and class 2 both are abstract ...

if a method in class1 is abstact ,,can i implement this method in class2 since it is abstact...
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. is class1 and class2 has any relation?

2. so far what you have done?
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can easily try this in your IDE (f.e. eclipse).

But, for now: Yes, this is possible. An abstract class can have both abstract AND implemented methods which are inherited from a super abstract class.

NOTE: You're not mentioning that class2 extends from class1. I'm assuming that that is what you're trying to do.
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Abstract classes can have non-abstract methods. For that matter you can have an abstract class with no abstract methods (though you would not want to do this). But a abstract method can only be present in an abstract class.
 
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mohamed Sanaulla wrote:For that matter you can have an abstract class with no abstract methods (though you would not want to do this).


You might want to do that. See HttpServlet, for example. Or java.awt.event.MouseAdapter. In both cases you need to override at least one of several methods to make it useful, but if they were marked abstract you'd have to implement all of them.
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Matthew Brown wrote:

Mohamed Sanaulla wrote:For that matter you can have an abstract class with no abstract methods (though you would not want to do this).


You might want to do that. See HttpServlet, for example.



Ah ok, but I think this is confusing right?
but the documentation says:

Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A subclass of HttpServlet must override at least one method, usually one of these:


And may be that is why its declared Abstract.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To me abstract just means "there's no reason to ever instantiate this, so stop anyone doing it, as it would be a mistake". It's a semantic issue. If you see something is abstract, you know it is only meant to be subclassed.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic