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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:37:35+00:00 2026-05-21T06:37:35+00:00

Here is the scenario: I have an interface A, 100 classes B0 … B99

  • 0

Here is the scenario: I have an interface A, 100 classes B0 … B99 that implement only A and 50 classes C0, C2 … C98 that extend B0, B2 … B98.

The B classes work with a MySQL database, doing various stuff on the tables.
The C classes add extra logic to B classes (validations, privileges etc).
The B classes are generated by a tool, while the C classes are written by a coder.

A client application will use the B classes and will not have access to C classes. When a method is called for a B object, the client will serialise the object and send it to a server application, along with the method name that is to be called.

The server will receive the B object and cast it as an A. However, the server would like to execute the method that was overridden in the C class if such a class exists, and the method from B otherwise. Normal behaviour would only execute the method from B.

How would the server be able to do that without having a huge SWITCH statement that would cast the received object to a C?

EDIT: I am new to java and did not know what reflection could do. With a little help from google (this and this) I solved my problem. I can use dynamic casting for what I want to achieve. Thanks to everybody.

  • 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-21T06:37:36+00:00Added an answer on May 21, 2026 at 6:37 am

    Well you have an object of runtime type B, and you are asking to call it as if it were an object of type C. This isn’t really how inheritance works; you cannot downcast to C unless it was originally created as a C, because in general, it doesn’t have all the fields of C.

    I am guessing your C classes do not add any additional fields to a B (if they did, your question wouldn’t make sense). Since they don’t add any additional fields, then I can see how it would make sense to treat them as a C, but there isn’t a really good way to do it. I would say:

    1. Why are there Bs and Cs in the first place? Why not just have B classes, with all the privileges, etc, and use that?
    2. Failing that, I suppose you could use reflection. Write some generic code that takes any of your B class objects, constructs a new corresponding C object, and copies over all of the fields.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my scenario - I have an SSIS job that depends on another prior
Here's the scenario: You have a Windows server that users remotely connect to via
Here's the scenario: I have a set of buttons that I want to bind
Here's my scenario: I have a simple stored procedure that removes a specific set
Ok, so here is the scenario: I have an activeX that uploads files using
Here's the scenario: I have a textbox and a button on a web page.
Here's the scenario: You have an ASP.Net application supported by a Microsoft SQL Server
Here's the scenario I have a Grid with some TextBlock controls, each in a
Here's my scenario: I have a page containing several links; each link is meant
Here is the scenario: I have two asp pages. a.aspx is layout and b.aspx

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.