Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 07-11-2009
Member
 
Join Date: Nov 2009
Posts: 583
Abstract class in Java

Hi
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.
Reply With Quote
  #2  
Old 07-11-2009
Member
 
Join Date: May 2008
Posts: 2,008
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();
}
Reply With Quote
  #3  
Old 07-11-2009
Member
 
Join Date: May 2008
Posts: 2,293
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();
}
Reply With Quote
  #4  
Old 07-11-2009
Member
 
Join Date: May 2008
Posts: 2,008
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();
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Abstract class in Java"
Thread Thread Starter Forum Replies Last Post
Static method in Abstract class Anthony12 Software Development 6 12-08-2010 10:22 AM
Problem with abstract class and interface Vodka Software Development 5 08-03-2010 12:20 PM
Difference among concrete class and abstract class Roxy_jacob Software Development 4 07-12-2009 01:22 PM
Abstract class and Interface in .net RogerFielden Software Development 3 04-05-2009 06:07 PM
What's the difference between an interface and an abstract class in JAVA? Vaibhav S Software Development 4 02-03-2009 08:46 PM


All times are GMT +5.5. The time now is 12:57 PM.