What is an abstract class?

What is an abstract class and what does it do compare to other classes?
I'm having some trouble trying to understand it.
Message was edited by:
xc100

s it not obvious that the OP is a worthless troll?Looking at his/her recent posts, I wouldn't say so.
S/he looks like a newbie who is asking basic
questions
and is rather reluctant to follow links or read
tutorial pages,
but I haven't seen actual troll behaviour.My first impression was that this was another Charles_Bronson, due to the countless threads that ask basic, open-ended questions.
Then again, CB never posted any actual code, so who knows?
One can never know really and it's unfair to judge someone unheard. That's >why I usually start by giving a very brief reply to invite to a dialog.
And it's not just about replying to the OP. Sometimes a discussion of >general interest develops even from a seemingly trivial question.I see your point. However, the discussions that seem to stem from these types of threads seem to be irrelevant to Java, if you know what I mean.

Similar Messages

  • What happens to abstract classes now?

    As we can write default implementations to the methods in a interface, what happens to abstract classes now?

    just because you can doesn't mean you should. And this is a clear case of you should not.
    Allowing implementation in interfaces is a dirty hack they needed to put in to be able to bolt on some of the other stuff without breaking forward compatibility with existing code.
    That doesn't make it a good idea, in fact it's a pretty good indication that the stuff they hacked in this way is itself not a good idea.

  • Casting & abstract class & final method

    what is casting abstract class & final method  in ABAP Objects  give   some scenario where  actually  use these.

    Hi Sri,
    I'm not sure we can be any more clear.
    An Abstract class can not be instantiated. It can only be used as the superclass for it's subclasses. In other words it <b>can only be inherited</b>.
    A Final class cannot be the superclass for a subclass. In other words <b>it cannot be inherited.</b>
    I recommend the book <a href="http://www.sappress.com/product.cfm?account=&product=H1934">ABAP Objects: ABAP Programming in SAP NetWeaver</a>
    Cheers
    Graham

  • How to use function of an abstract class??

    Hi all,
    I want to use the format(object obj) function of the package java.text.Format. But as the Format class is an abstract class i could not instantiate it, so that i can call the format(object obj) method using the dot(.) operator.
    I know what is an abstract class. i've studied and tried to understand. as everybody knows, studied the perfect example(because i've read it in all the abstract class tutorial, books) of the Shape class. But still i dont understand how am i going to use that format(object obj) method. Please help me..

    Instead of using the abstract class Format use the
    concrete classes DecimalFormat
    SimpleDateFormat etc check java.text APIS
    http://java.sun.com/j2se/1.4.2/docs/api
    Hi!! Thanks both of you.
    If Sun has a abstract class then there must be a
    concrete class which extends that abstract class .It
    is always better to check the APIWhat do you mean by this line. Is it true for all the abstract classes in the jdk?

  • What is the diff b/w Abstract class and an interface ?

    Hey
    I am always confused as with this issue : diff b/w Abstract class and an interface ?
    Which is more powerful in what situation.
    Regards
    Vinay

    Hi, Don't worry I am teach you
    Abstract class and Interface
    An abstract class can have instance methods that implement a default behavior. An Interface can only declare constants and instance methods, but cannot implement default behavior and all methods are implicitly abstract. An interface has all public members and no implementation. An abstract class is a class which may have the usual flavors of class members (private, protected, etc.), but has some abstract methods.
    Edited by SASIKUMARA
    SIT INNOVATIONS- Chennai
    Message was edited by:
    sasikumara
    Message was edited by:
    sasikumara

  • What is the point of an abstract class?

    ok lets say there was a subclass that inhereited another subclass...like a class Person, a class Student, and a class GraduateStudent; why would i want to make the class person abstract and have a abstract void display(); in it if i want to override that method in the subclasses lower on the inheritance tree? Wouldn't it do the same thing to just make a normal class Person and just not have a void display...and the other 2 over ride it anyways so i seriously dont see what the point of abstract classes are

    ok lets say there was a subclass that inhereited
    another subclass...like a class Person, a class
    Student, and a class GraduateStudent; why would i
    want to make the class person abstract and have a
    abstract void display(); Because all Persons are required to be able to display(), but there's no reasonable common default behavior for display() that you can put in the base class.
    Abstract methods say, "Everything of this type must be able to do this, but it's up to the individual implementations to figure out *how* to do it."
    in it if i want to override
    that method in the subclasses lower on the
    inheritance tree? Wouldn't it do the same thing to
    just make a normal class Person and just not have a
    void display..Then you couldn't do this: Person p = getAPersonThatMightBeAStudentOrWhateverWeDoNotKnowWhat();
    p.display();or this:
    void doPersonStuff(Person p) {
      p.display();
    Person s1 = new Student();
    Student s2 = new Student();
    Person t1 = new Teacher();
    Teacher t2 = new Teacher();
    doPersonStuff(s1);
    doPersonStuff(s2);
    doPersonStuff(t1);
    doPersonStuf(t2);
    .and the other 2 over ride it anyways
    so i seriously dont see what the point of abstract
    classes areI hope you do now.
    Message was edited by:
    jverd

  • What is the advantage of abstract class and method???

    hi,
    * Why a class is declared as abstract???
    * What is the use of declaring a class as abstract???
    * At what situation abstract class will be used???Thanks
    JavaImran

    To save you from the wrath of the Java experts on this forum, allow me as a relatively new Java user to advise you: do NOT post homework problems here; you're just going to get told to go google the answer. Which would be a good move on your part. Especially since I found the answer to your questions by googling them myself.

  • What is Abstract class

    Hello what is Abstract class

    An abstract class is a class that can have one or more abstract methods in it.
    An abstract method is a method that does not have a body. Only the signature is declared, leaving it up to a subclass to implement the method.
    An often used example of this would be the abstract class shape, representing a two dimensional shape (for instance a circle or a square). This class has an abstract method getArea(), which gets you the size of the surface.
    The implementation of this method would be something like returning Math.PI * radius * radius for the circle, while returning side * side for the square.
    So while you can't do something like Shape s = new Shape(), you can do Shape s = new Square() and int x = s.getArea() after that.

  • What is the benefit of abstract classes?

    I am little bit confuse regarding the benefits of the abstract classes. Can anybody helps me in this regard. I just want to know when and what situation we may decide that particular class needs an abstract method.
    Thanx

    I am little bit confuse regarding the benefits of the
    abstract classes. Can anybody helps me in this
    regard. I just want to know when and what situation
    we may decide that particular class needs an abstract
    method.Sorry if I sound weary of this question, but it is asked about 3-4 times a week. Rather than have us go through this tired exercise again, please search the forum for previous threads on this subject. You'll find about a gazillion. In fact, it's often a good idea to search the forum before asking a question as very often it has been asked and answered before.

  • What's the difference between Abstract Class and Interface?

    Dear all,
    Can anyone give me some hints about this topic?
    Thanks.
    Leo

    an abstract class may have some methods already implemented in the abstract class but an interface has no methods implemented
    I think it's just that simple.
    For your design needs, you just choose what you need : )
    Cheers
    Stephen

  • What are abstract classes/methods and what are they for?

    Hi,
    I've just heard about abstract classes and methods and I'm just wondering what exactly they're used for, and why are they there for the Graphics class for example?
    Cheers.

    raggy wrote:
    bastones_ wrote:
    Hi,
    I've just heard about abstract classes and methods and I'm just wondering what exactly they're used for, and why are they there for the Graphics class for example?
    Cheers.Hey bro, I'll try to solve your problemYou have to know two important concepts for this part. 1 is Abstract classes and the other is Interface classes. Depends on the nature of the project, you need to set certain level of standards and rules that the other developers must follow. This is where Abstract classes and Interface classes come into picture.
    Abstract classes are usually used on small time projects, where it can have code implementation like general classes and also declare Abstract methods (empty methods that require implementation from the sub-classes).Wrong, they are used equally among big and small projects alike.
    Here are the rules of an Abstract class and method:
    1. Abstract classes cannot be instantiatedRight.
    2. Abstract class can extend an abstract class and implement several interface classesRight, but the same is true for non-abstract classes, so nothing special here.
    3. Abstract class cannot extend a general class or an interfaceWrong. Abstract classes can extend non-abstract ones. Best example: Object is non-abstract. How would you write an abstract class that doesn't extend Object (directly or indirectly)?
    4. If a class contains Abstract method, the class has to be declared Abstract classRight.
    5. An Abstract class may or may not contain an Abstract methodRight, and an important point to realize. A class need not have abstract methods to be an abstract class, although usually it will.
    6. Abstract method should not have any code implementations, the sub-classes must override it (sub-class must give the code implementations). An abstract method must not have any implementation code code. It's more than a suggestion.
    7. If a sub-class of an Abstract class does not override the Abstract methods of its super-class, than the sub-class should be declared Abstract also.This follows from point 4.
    9. Abstract classes can only be declared with public and default access modifiers.That's the same for abstract and non-abstract classes.

  • What is the difference between Abstract class and Interface ?

    Hi,
    Could u plz tell me the difference between Abstract class and Interface?
    Thanks in advance.
    Gopi

    Lots.
    An abstract class can contain some method implementations, or indeed all the method implementations. It may contain methods with all the various access modifiers. It cannot be instantiated. A class may inherit from only a single abstract class.
    An interface contains only public method stubs and constants. A class may implement multiple interfaces. An interface cannot (obviously) be instantiated.
    Abstract classes are particularly useful when you need to provide a semi-complete implementation for reuse. Interfaces are used more like types.
    Look at java.util.* for some good examples of the use of both.

  • Abstract method called in an abstract class

    Hello,
    I am writing some code that I'd like to be as generic as possible.
    I created an abstract class called Chromozome. This abstract class has a protected abstract method called initialize().
    I also created an abstract class called Algorithm which contains a protected ArrayList<Chromozome>.
    I would like to create a non abstract method (called initializePopulation()) which would create instances of Chromozome, call their method initialize() and full the ArrayList with them.
    In a practical matter, only subclass of Algorithm will be used, using an ArrayList of a subclass of Chromozome implementing their own version of initialize.
    I have been thinking of that and concluded it was impossible to do. But I'd like to ask more talented peaple before forgetting it !
    Thanks,
    Vincent

    Ok, let's it is not impossible, juste that I had no idea of how doing it :-)
    The difficulty is that Algorithm will never have to deal with Chromozome itself, but always with subclass of Chromozome. This is usually not an issue, but in that case, Algorithm is required to create instances of the desired subclass of Chromozome, but without knowing in advance wich subclass will be used (I hope what I say makes any sense).
    Actually I may have found a way in the meantime, but maybe not the best one.
    I created in Algorithm an abstract method :
    protected abstract Chromozome createChromozome()The method initializePopulation will call createChromozome instead of calling directly the constructor and the initialize() method of Chromozome.
    Then subclass of Algorithm will implement the method createChromozome using the desired subclass of Chromozome.

  • "Abstract" method in a non-abstract class

    Hi all.
    I have a class "SuperClass" from which other class are extended...
    I'd like to "force" some methods (method1(), method2, ...) to be implemented in the inherited classes.
    I know I can accomplish this just implementing the superclass method body in order to throw an exception when it's directly called:
    void method1(){
    throw new UnsupportedOperationException();
    }...but I was wondering if there's another (better) way...
    It's like I would like to declare some abstract methods in a non-abstract class...
    Any ideas?

    The superclass just models the information held by
    the subclasses.
    The information is taken from the database, by
    accessing the proper table (one for each subclass).??
    What do you mean by "models the information"?
    You should use inheritance (of implementation) only when the class satisfies the following criteria:
    1) "Is a special kind of," not "is a role played by a";
    2) Never needs to transmute to be an object in some other class;
    3) Extends rather than overrides or nullifies superclass;
    4) Does not subclass what is merely a utility class (useful functionality you'd like to reuse); and
    5) Within PD: expresses special kinds of roles, transactions, or things.
    Why are you trying to force these mystery methodsfrom the superclass?
    It's not mandatory for me to do it... I 'd see it
    just like a further way to check that the subclasses
    implements these methods, as they have to do.That's not a good idea. If the superclass has no relation to the database, it shouldn't contain methods (abstract or otherwise) related to database transactions.
    The subclasses are the classes that handle db
    transaction.
    They are designed as a binding to a db table.And how is the superclass designed to handle db transactions? My guess (based on your description) is that it isn't. That should tell you right away that the subclasses should not extend your superclass.

  • When we will go for an abstract class and when we will go for an interface?

    it's always some what confusing to choose an abstract class and an interface,can anybody post a suitable answer for this.

    jwenting wrote:
    with experience and the insight it brings, you will know which to use when.
    Without it, it can't be explained.
    More often than not there's no X OR Y anyway.It's fortunate that there are posters here who possess the insight and experience necessary to explain this. The principal differences between an abstract class and an interface are,
    1. An abstract class can carry implementation, whereas an interface cannot.
    2. An abstract class is singly inherited, wheras an interface is multiply inherited.
    So use an abstract class when the implementation it can carry outweights the fact that it cannot be multiply inherited That's the gist of it.
    The inheritance relationship where this happens is when the supertype is a general concept of which all potential subtypes are special cases. This is called a specialization (or sometimes a generalization) relationship. For example Apple and Banana are Fruit. Or Car and Bike are Vechicle. The Fruit and Vechicle supertypes are general concepts of which their subtypes are special cases. In this case make Fruit and Vechicle abstract classes because the subtypes will benefit from a shared implementation.
    If you don't have a clearcut specialization/generalization relationship make the supertype an interface. An example could be the Comparable supertype. The potential subtypes aren't supposed to be specializations of the Comparable concept, they're suppose to become Comparable (and make this property an integral part of their being). This is not a specialization/generalization relationship. Instead the supertype is intended to add character to the subtypes. The subtypes are unlikely to benefit from an inherited implementation. So make Comparable an interface.

Maybe you are looking for