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

The Archive Base Latest Questions

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

I was wondering if I could have the parent class instantiate an object of

  • 0

I was wondering if I could have the parent class instantiate an object of a child class, without going into an infinite recursion.

Consider this example:

Module Module1
    Sub Main()
        Dim _baseFruit As New Fruit
        _baseFruit.Write()

        Console.ReadKey()
    End Sub
End Module

Public Class Fruit
    Public Property Type As String
    Public Property BaseType As String
    Public Property FruitType As New Apple

    Sub New()
        Type = "Fruit"
        BaseType = "N/A"
    End Sub

    Public Sub Write()
        Console.WriteLine("Type: {0} BaseType: {1} FruitType: {2} ", Type, BaseType, FruitType.Type)
    End Sub
End Class

Public Class Apple
    Inherits Fruit

    Public Sub New()
        Me.Type = "Apple"
    End Sub
End Class

As soon as an Apple is instantiated, it’s entering the infinite recursion.

Is it incorrect to say this is impossible, that is to have a child referenced in the parent which is also the base ?

EDIT: From the answer below I have updated the code, lo and behold, it works.

Module Module1
    Sub Main()
        Dim _baseFruit As New Fruit
        Dim _apple As New Apple

        _baseFruit.Write(_apple)
        Console.ReadKey()
    End Sub
End Module

Public Class Fruit
    Public Property Type As String
    Public Property BaseType As String
    Public Property FruitChildInstance As Apple

    Sub New()
        Type = "Fruit"
        BaseType = "N/A"
    End Sub

    Public Sub Write(ByVal fruit As Apple)
        FruitChildInstance = fruit
        Console.WriteLine("Type: {0} BaseType: {1} FruitType: {2} ", Type, BaseType, FruitChildInstance.Type)
    End Sub
End Class

Public Class Apple
    Inherits Fruit

    Public Sub New()
        Me.Type = "Apple"
    End Sub
End Class
  • 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-26T08:28:05+00:00Added an answer on May 26, 2026 at 8:28 am

    This could be called an “infinite type”. It doesn’t have to be a problem if you allow the member variable to be left empty.

    Without looking at the actual meaning of this code, you could say this:

    Dictating that the FruitType member has to be an Apple instance results in an infinite amount of objects nesting. Leaving it uninitialized (Dim FruitType as Fruit) would cause no problem at all.

    Now when you do take the semantic into account:

    You’re mixing the “Type” concept with the “Instance” concept: a Fruit instance has-a type (e.g. the class Apple), but it’s quite strange to let it have-a Fruit member, too.

    If you would have modeled this as a class FruitType, where a Fruit has a member dimensioned FruitType, the infinite recursion wouldn’t have happened.

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

Sidebar

Related Questions

I was wondering if someone could help me with this. I have defined my
I have a MovieClip that is composed in a parent (non-display object) class. We
I was wondering if the following could be achieved in xml: I have this
Wondering if someone could help me. I have next to no knowledge with Ajax,
I was wondering if any one could help me out; I have a table
I have been wondering and couldn't find a clear answer on this subject. Imagine
I was wondering how I could use JQuery to select the child of a
I was wondering if anyone could help me with this problem i'm having. I
I have an entity class, correctly defined in a managed context. This class has
I am wondering how I could delete an object depending on it's title for

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.