Posted on 2004-11-26
Last Modified: 2010-03-31
Hi all,

what exactly are abstracts, on what conditions are they used and how could they be used? Examples would be greatly appreciated. Thanks..
Question by:eturfclub
    LVL 13

    Expert Comment


    Abstract is a class that can't be instantiated because it has one or more abstract method, Any number of Classes can extend this abstract and implment the abstract methods hence can be instantiated, refer to this article contains samples:
    LVL 8

    Accepted Solution

    An formally unfinished class or method, marked with the keyword abstract. An abstact class is deliberatesly missing some or all of the method bodies. An abstract method is deliberately missing its method body. An abstract class is similar to an interface which is missing all the method bodies. An abstract class provides a base for someone to extend an actual class. You can't use new on abstract classes, but you can use abstract references, which always point to some extension of the abstract class. Interfaces are implicitly abstract as are alls their methods.

    abstract class
    A class that is missing definitions for one or more methods. You can't thus create an object of that class. You must first create a subclass and provide definitions for the abstract methods. Unlike interfaces, abstract classes may implement some of the methods. Though you can't instantiate an abstract class, you can invoke its static methods.

    find some more information ............

    Simple Example
    import java.util.*;

    abstract class Instrument4 {
      int i; // storage allocated for each
      public abstract void play();
      public String what() {
        return "Instrument4";
      public abstract void adjust();

    class Wind4 extends Instrument4 {
      public void play() {
        System.out.println(" plays test");
      public String what() { return "Wind4"; }
      public void adjust() {}

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Suggested Solutions

    Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
    Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
    This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now