aspose file tools*
The moose likes Beginning Java and the fly likes abstract class and interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "abstract class and interface" Watch "abstract class and interface" New topic
Author

abstract class and interface

amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
When do we use an abstract class and when do we use an interface?
El Roy Cabildo
Greenhorn

Joined: Oct 19, 2002
Posts: 23
interface is a collection of methods..view it as a template which those methods should be implemented when sub classed..while abstract is a partial class means their is a method that don't have implementation..means subclassing a abstract class should implement its abstract method otherwise declare the child as abstract...just like for example...
A class Human...not all human do smoke() so you make it as an abstract so...if you create a class named Amit and subclass the Human class and amit do Smoke() you implement that you do smoke.
amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
that means when we want only some methods to be implemented then we use abstract class otherwise we use interface.
The decision of whether to create an abstract class or an interface depends on the design. right??
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi amit,
yes. it depends on how u think and what u have in front of u.
in one application something can be an interface but in the other application we would love to create an abstract class instead...you know...
also, in creating abstract class the risk is that the implementing class can't extend other class. so we might be in trouble due to this.
though i've not come across such a thing so far.
regards
maulin.
amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231
thanks
Brian Burke
Greenhorn

Joined: Oct 26, 2000
Posts: 15
amit,
another distinction that maulin touched on is that an interface is implemented and an abstract class is sublassed. For example. If you have a Human interface (to steal the example from above) you would say.
public class DoSomething implements Human{ }
Whereas if Human is an abstract class, it would look like.
public class DoSomething extends Human{ }
You can implement multiple interfaces, but can only subclass one class.
HTH,
Brian
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: abstract class and interface
 
Similar Threads
Interface vs abstract class
Abstract class
Real Time Scenerio for abstract class and interface
when to use interface and when abstract class
Abstract Class & Interface