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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:54:21+00:00 2026-05-13T10:54:21+00:00

I have an external API (I can’t modify it) with class A and local

  • 0

I have an external API (I can’t modify it) with class “A” and local class “B” which overrides methods of “A” and adds an additional function.
I need to use one of them according to some parameter “is_A”.

/—— API (A.java) —–/

package A;

public class A {

    public int pingA( int value ) {

        return value;

    }

}

/—— my class (B.java) —–/

package B;

import A.*;

public class B extends A {

    @Override
    public int pingA( int value ) {
        return value;
    }

    public int pingB( int value ) {
        return value;
    }

    public static void main(String[] args) {
        final boolean is_A = false;
        A obj;
        if (is_A) {
            obj = new A();
        } else {
            obj = new B();
        }
        if (!is_A) {
            int n = obj.pingB(3);
        }
    }
}

In this case I want to use class “B”, but the command “int n = obj.pingB(3);” is not compiled because there is no method pingB in A.
The exact message is:

cannot find symbol
symbol: method pingB(int)
location: class A.A
  • 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-13T10:54:21+00:00Added an answer on May 13, 2026 at 10:54 am

    You need to cast obj back to B.

    if (!is_A) {
        int n = ((B) obj).pingB(3);
    }
    

    You can by the way better use the instanceof keyword instead of is_A.

    if (obj instanceof B) {
        int n = ((B) obj).pingB(3);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're designing a HTTP service with an external API, which will need to store
Is it possible to have a C++ template function which can access different fields
I have a List of List<String> 's which I get from a external API
I have a method wrapping some external API call which often returns null .
I have a form which is posted to an external API. There is a
I have a compiled C/C++ Dll. I would like to know which external API
I have external html5 canvas that you can paint on some lines using your
I have an external file with some vars to require in my php class
I have scripts from external domains that access our api script on our server,
I have a ASP.Net C# application that needs to connect to an external API

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.