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

  • Home
  • SEARCH
  • 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 6219007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:42:22+00:00 2026-05-24T07:42:22+00:00

I am trying to use template design pattern so I use abstract class to

  • 0

I am trying to use template design pattern so I use abstract class to define my algorithm like this:

abstract class MyTemplate
{
    public void execute()
    {
       //... do something
       doSomething();
    }
    public abstract void doSomethig();
}

In my code I will create an instanceof MyTemplate everytime like this:

MyTemplate cleanUp = new MyTemplate()
{

public void doSomething()
{
// execute cleanup 
}
}
cleanUp.execute();

Is creating a object out of abstract class expensive for JVM?

Thanks,

Sean Nguyen

  • 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-24T07:42:22+00:00Added an answer on May 24, 2026 at 7:42 am

    You’re not really creating an abstract class instance. You’re creating an instance of a concrete class which happens to have no name in your code, created by the Java compiler.

    The JVM doesn’t really know or care about that – so it’s only as expensive as creating an instance of any other class which happens to be a subclass of an abstract class. So don’t sweat it 🙂

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

Sidebar

Related Questions

I'm trying to use type traits like in Modern C++ Design using a template
I'm trying to use a class within a T4 template in VS2008. Here is
I'm trying to use an instant of a custom class as a template parameter.
I am trying to determine the best design pattern to use for a business
I am trying to use JQuery to parse a sitemap.xml to look like this
I am trying to use a template that contains a link such as this:
I'm trying to use both extends and include tags in one template, just like:
I am trying to use template meta-programming to determine the base class. Is there
I'm practicing C# with wpf and I'm trying to use template formatting. At this
I'm going a little nuts trying to figure out how to use template inheritance

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.