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.
Code:
public abstract class GraphicObject {
// declare fields
// declare non-abstract methods
abstract void draw();
}
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.
Code:
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();
}
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.
Code:
abstract class Shape {
public String color;
public Shape() {
}
public void setColor(String c) {
color = c;
}
public String getColor() {
return color;
}
abstract public double area();
}