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 7535165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T06:14:45+00:00 2026-05-30T06:14:45+00:00

Abstract classes cannot be instantiated in java. But spring says something like bean creation

  • 0

Abstract classes cannot be instantiated in java. But spring says something like bean creation with abstract="true". If a state of an abstract class is initialised only by its child class instance(i guess i am right), then if i need to use that attribute inside the method which is defined in the abstract class then… is there a possibility for it? I have a set of code as follows:

class abstract A { 
    private Something somethingObj; 
    // getters and setters are present.

    public void logSomething() { 
        try{ 
           //some code which throws exception 
        }
        catch(Exception e){ 
            somethingObj.logIt(e);// I have some logic inlogIt method. 
        } 
    }
}
  • 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-30T06:14:46+00:00Added an answer on May 30, 2026 at 6:14 am

    Abstract beans in Spring are somewhat different from abstract classes. In fact, abstract bean in Spring doesn’t even have to be mapped to any class. Take this as an example:

    <bean id="dao" abstract="true">
        <property name="dataSource" ref="dataSource"/>
        <property name="someHelper" ref="someHelper"/>
    </bean>
    
    <bean id="fooDao" class="FooDao" parent="dao">
        <property name="fooHelper" ref="fooHelper"/>
    </bean>
    <bean id="barDao" class="BarDao" parent="dao">
        <property name="barHelper" ref="barHelper"/>
    </bean>
    

    And classes:

    public class FooDao {
        private DataSource dataSource;
        private SomeHelper someHelper;
        private FooHelper fooHelper;
    
        //setters
    }
    
    public class BarDao {
        private DataSource dataSource;
        private SomeHelper someHelper;
        private BarHelper barHelper;
    
        //setters
    }
    

    Note that FooDao and BarDao do not have any parent (abstract or not) base class in common. Parent abstract bean definition is used only to group common properties, so you avoid repetition in XML.

    On the other hand introducing abstract Dao class that both FooDao and BarDao inherit from would be a good idea:

    public abstract Dao {
        protected DataSource dataSource;
        protected SomeHelper someHelper;
    
        //setters
    }
    
    public class FooDao extends Dao {
        private FooHelper fooHelper;
    
        //setters
    }
    
    public class BarDao extends Dao {
        private BarHelper barHelper;
    
        //setters
    }
    

    But still dao bean doesn’t have to define a class. Treat abstract beans as a way to reduce duplication in XML when several concrete beans have same dependencies.

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

Sidebar

Related Questions

URL: Link (1) According to this wesbite .. you cannot implement Abstract classes but
I have 3 abstract classes (Customer, Tender, Site). For Customer has inherited class such
Is it good practice to let abstract classes define instance variables? public abstract class
I currently have 2 concrete methods in 2 abstract classes. One class contains the
Abstract classes and interfaces play very a important role in Java and they have
If I have an abstract class like this: public abstract class Item { private
1) OnCreate is public method of instantiated object from ClsLast class. But I wanted
I have just implemented some classes: public abstract class Job<T extends ViewerUnion>{ [...] }
I'm writing a large abstract base class with 30 something purely virtual methods*. Finding
MSDN defines System.Enum as an abstract class: [SerializableAttribute] [ComVisibleAttribute(true)] public abstract class Enum :

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.