Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6678793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:17:04+00:00 2026-05-26T04:17:04+00:00

I understand what an abstract class is in OOP paradigm. Yeah an abstract class

  • 0

I understand what an abstract class is in OOP paradigm. Yeah an abstract class is an incomplete type, cannot be instantiated.

Subclasses of the abstract class can extend the superclass and so on, and call a method through using a base type variable. But that is what I don’t get.

I was reading the book, and the author said using a Superclass variable to reference a subclass and calling a common method calls the correct method. And yeah that’s true. For example this little code I wrote:

public class ObjectOne extends SuperObject {

    public String objectString()
    {
        return "objectString() of class ObjectOne\n" ;
    }
}



public class ObjectTwo extends SuperObject {

    public String objectString()
    {
        return "objectString() of class ObjectTwo\n" ;
    }
}


public class ObjectThree extends SuperObject {

    public String objectString()
    {
        return "objectString() of class ObjectThree\n" ;
    }
}


public class SuperObject {
    public String objectString()
    {
        return "SuperObject" ;      
    }
}

    import static java.lang.System.out ;
public class ControlClass {

    public static void main(String[] args)
    {
        SuperObject [] arr = {new ObjectOne(), new ObjectTwo(), new ObjectThree()} ;

        for(SuperObject elem:arr)
        {
            out.println(elem.objectString()) ;
        }
    }
}

Em, so when main executes the correct methods are called for the objects using just the reference type. My question is so what is the point of an abstract class? Polymorphism works regardless of whether the method or class is abstract.
Unlike C++, polymorphism works only when you specify it. For Java, it works apparently all the time.

So I guess the abstract keyword or abstract concept is just to complete the inheritance hierarchy, make incomplete types impossible to instantiate, or is to promote good OOP practice? Can someone clarify thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:17:05+00:00Added an answer on May 26, 2026 at 4:17 am

    I’m not sure you understand what an abstract class is, as none of the classes in your example are abstract, and nothing in there is an interface either. What you are doing is extending an instantiable class. Without the abstract keyword there is nothing to stop me doing:

    SuperObject obj = new SuperObject();

    I think a better example would be to illustrate how abstract classes are used. What they are commonly used to do is to provide a common method implementation. If a number of classes implement some interface, but all of them implement the same method in the same way using the same code, then what is commonly done is to create an abstract class that contains the common implementation, and get all of the concrete implementations to extend that class. This facilitates code reuse, and decreases the likelihood that one developer will change the common method implementation for one class, but forget the others. For example..

    public class ObjectOne extends Thing {
      public String objectString()
      {
          return "objectString() of class ObjectOne\n" ;
      }
    }
    
    public class ObjectTwo extends Thing {
      public String objectString()
      {
        return "objectString() of class ObjectTwo\n" ;
      }
    }
    
    public class ObjectThree extends Thing {
      public String objectString()
      {
        return "objectString() of class ObjectThree\n" ;
      }
    }
    
    public abstract class Thing implements SuperObject {
      public String alwaysTheSame() {
        return "The same thing";
      }
    }
    
    public interface SuperObject {
      public String objectString();
    
      public String alwaysTheSame();
    }
    
    import static java.lang.System.out ;
    
    public class ControlClass {
    
      public static void main(String[] args)
      {
        SuperObject [] arr = {new ObjectOne(), new ObjectTwo(), new ObjectThree()} ;
    
        for(SuperObject elem : arr)
        {
            out.println(elem.alwaysTheSame());
            out.println(elem.objectString()) ;
        }
      }
    }
    

    What we have done here is introduce an abstract class Thing, which provides a method implementation that is common to all 3 implementations of SuperObject (which is now an interface). This means we don’t have to write the same code again in three different places in order to to fully implement the SuperObject interface in each one of our concrete classes.

    In addition to this, you can also extend non final classes. You may wish to do this in order to override the default behaviour of one or methods on the concrete class, or to decorate the the class with additional methods. Of course, when you are designing a class hierarchy from scratch you don’t stick concrete classes in it that then get extended by other classes, as it’s generally considered a bad code smell. However, few of us work with totally new written-from-scratch codebases, and must adapt an exiting codebase to new requirements. Extending a concrete class is one tool in the toolbox to do this.

    EDIT: Misunderstood what the OP was asking, but the last paragraph above is relevant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I understand that neither a abstract class nor an interface can contain a method
What's the point of using abstract methods? An abstract class cannot be instantiated, but
First off, I understand the reasons why an interface or abstract class (in the
Given this: abstract class ViewPresenterPair { type V <: View type P <: Presenter
Can I create instance of abstract class in C#/.net like in Java ? Additional
I'm trying to understand the IntentService class so that I can build my own
Can you give me an almost overly simplistic understanding of abstract class vs inheritance
Possible duplicate: why-is-java-lang-throwable-a-class Hi! I doesn't understand why Throwable isn't abstract class. I see
So, for example, StringBuilder inherits from the abstract class AbstractStringBuilder . As I understand
I understand that one can raise an event in the class that the implementation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.