TechArena Community

TechArena Community (
-   Software Development (
-   -   Abstract class in Java (

SoftWore 07-11-2009 01:47 PM

Abstract class in Java
Can any one explain me the concept of abstract classes in java. I am confused between the normal class and the abstract class. I am clear with the normal class concept in java. I think I am little confused with abstract classes. A few examples and some explanation can help me out. Hoping for a reply.

Katty 07-11-2009 01:52 PM

Re: Abstract class in Java
An abstract class is a class that is declared abstract?it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be sub-classed. An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon). The following code is generally how you declare abstract classes.

public abstract class GraphicObject {
  // declare fields
  // declare non-abstract methods
  abstract void draw();

Zecho 07-11-2009 01:55 PM

Re: Abstract class in Java
This is a more detailed code for abstract class. Just go through the following code, it will definitely help you.

public abstract class Place {
String Name;
String Postcode;
String County;
String Area;
Place () {
public static Place make(String Incoming) {
        if (Incoming.length() < 62) return (null);
        String Name = (Incoming.substring(4,26)).trim();
        String County = (Incoming.substring(27,48)).trim();
        String Postcode = (Incoming.substring(48,61)).trim();
        String Area = (Incoming.substring(61)).trim();
        Place created;
        if (Name.equalsIgnoreCase(Area)) {
                created = new Area(Area,County,Postcode);
        } else {
                created = new District(Name,County,Postcode,Area);
        return (created);
public String getName() {
        return (Name);
public String getPostcode() {
        return (Postcode);
public String getCounty() {
        return (County);
public abstract String getArea();

Katty 07-11-2009 01:58 PM

Re: Abstract class in Java
Even this is a simple example to use understand. If you are new to java, so through the simple examples first and the complex once.

abstract class Shape {
 public String color;
 public Shape() {
 public void setColor(String c) {
  color = c;
 public String getColor() {
  return color;
 abstract public double area();

All times are GMT +5.5. The time now is 06:29 PM.