David W's answer was only partly correct. An abstract class can in fact have concrete methods. Actually, an abstract class can have a complete implementation, but be declared "abstract". The impact is that the class must be subclassed in order to create an instance. In general, though, an abstract class will have at least one method that is declared abstract and must be implemented by a subclass.
I like to use abstract classes as a design approach where I want to specify a "plan" which may have some parts implemented, but which leave some details to be implemented by the developer using my design.
Example:
public abstract class SalesItem{
private double fPrice;
public SalesItem(double price){
fPrice = price;
}
public double getPrice(){
return fPrice;
}
public abstract getDescription();
}
public class CD extends SalesItem{
String fArtist;
String fTitle;
public CD(String artist, String title){
fArtist = artist;
fTitle = title;
}
//add "get" methods for title and artist
//override/implement getDescription() (was abstract)
public String getDescription(){
String desc = "CD: " + fArtist + ": " + fTtitle + " - $" + getPrice();
//note: look at DecimalFormat to format into just 2 decimal places
return desc;
}
}
2006-11-06 12:53:13
·
answer #1
·
answered by vincentgl 5
·
2⤊
0⤋
Abstract can be changed,
concrete is fixed
2006-11-06 02:00:58
·
answer #2
·
answered by Intellithug 3
·
1⤊
1⤋
abstract class are class with no implementation, its implementation is dynamic when you need it, the class itself is stable, but implementation is flexible, so the program can be easy modified
concrete class, i hope you get the term correct
2006-11-06 02:00:31
·
answer #3
·
answered by david w 5
·
1⤊
0⤋