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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:30:11+00:00 2026-06-12T03:30:11+00:00

Please consider the following scenario: Class Class1 Function Func() as String End Function End

  • 0

Please consider the following scenario:

Class Class1
 Function Func() as String
 End Function
End Class

Class Class2
 Function Func() as String
 End Function

 Function Func2() as String 
 End Function
End Class 

Class Class3

Function GetClassObject as Object
 If (certain condition meets)
   return new Class1();
 Else
  return new Class2();
 End If
End Function

Main()
Object obj1 = GetClassObject();
obj1.Func(); // Error: obj1.Func() is not defined:
End Main

End Class

Question: How to access obj1.Func() given the condition that for some reason I cannot inherit Class1 and Class2 from a common Interface class?

Thank you

Update:
One approach I used to address the problem and failed is as follows:

    Interface ICommon
     Function Func() as string
    End Interface

    Class Class3
    ...
        Main()

        Dim obj1 as ICommon = TryCast(GetClassObject(), ICommon); //Error: obj1 is "Nothing"
        obj1.Func()

or simply: 

TryCast(GetClassObject(), ICommon).Func() //Error: obj1 is Nothing

        End Main
    ...
    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-06-12T03:30:13+00:00Added an answer on June 12, 2026 at 3:30 am

    You can try this

    Object obj1 = GetClassObject();
    
    If TypeOf obj1 Is Class1 Then 
       DirectCast(obj1 , Class1).Func()
    ElseIf TypeOf obj1 Is Class2 Then 
       DirectCast(obj1 , Class2).Func()
    End If
    

    Or You can also try

    Dim c1 As Class1 = TryCast(obj1, Class1) 
    IF Not c1 Is Nothing Then
        c1.Func()
    Else
       Dim c2 As Class2 = TryCast(obj1, Class2) 
       IF Not c2 Is Nothing Then
          c2.Func()
       End If
    End If
    

    Or you can try With Reflection.

    Dim result as String = obj1.GetType().GetMethod("Func").Invoke(obj1, null)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider the following code: public class Person ( public string FirstName {get; set;}
Please consider the following code implementing a simple MixIn : class Story(object): def __init__(self,
Please consider the following code implementing a simple MixIn : class Story(object): def __init__(self,
Please consider the following scenario. I have a form with a property: class MyForm
Please consider the following class. I'm beginning to use JQuery. function AutoHide(elemControl, elemContent) {
Please consider the following java source: package com.stackoverflow; public class CondSpeed { private static
Please consider the following simple use case: public class Foo { public virtual int
Please consider the following three .NET types: I have an interface, an abstract class,
Please consider the following string $text = Dat foo 13.45 and $600 bar {baz:70}
Please consider the following function body: var isValidated = true; $(selector1).each(function(){ //do validation with

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.