Results 1 to 4 of 4

Thread: Abstract class in Java

  1. #1
    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.

  2. #2
    Join Date
    May 2008
    Posts
    2,012

    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();
    }

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    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();
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    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();
    }

Similar Threads

  1. Static method in Abstract class
    By Anthony12 in forum Software Development
    Replies: 6
    Last Post: 12-08-2010, 10:22 AM
  2. Problem with abstract class and interface
    By Vodka in forum Software Development
    Replies: 5
    Last Post: 08-03-2010, 12:20 PM
  3. Difference among concrete class and abstract class
    By Roxy_jacob in forum Software Development
    Replies: 4
    Last Post: 07-12-2009, 01:22 PM
  4. Abstract class and Interface in .net
    By RogerFielden in forum Software Development
    Replies: 3
    Last Post: 04-05-2009, 06:07 PM
  5. Replies: 4
    Last Post: 02-03-2009, 08:46 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,103,980.05352 seconds with 16 queries