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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:04:55+00:00 2026-06-14T17:04:55+00:00

I have a child class to handle images dragged onto the screen. It stores

  • 0

I have a child class to handle images dragged onto the screen. It stores the name, and x, y position of each image in variables. Then it has a methods to scale them and do other operations.

I would like to have 2 of these classes, but the image name and x, y position would be different.

I first tried to create a class that has this class as a child class. In this parent class, I tried creating the same variables, hoping it would use these, instead of the ones created in the child class.

The child class still used the variables created within it, instead of in the parent.

Is there a way to do this, or am I climbing up the wrong tree?

public class cShapeParent extends cShapes {

    // would like the base class to use this data
    String[] mNames=
    {
        "ball_green.png",
        "ball_green.png",
        "ball_green.png"    
    };

    cShapeParent(Context context,int screenWidth, int screenHeight)
    {
        super(context, screenWidth, screenHeight);
    }
}

Child class

import java.io.IOException;
import java.io.InputStream;

import android.content.Context;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;

public class cShapes {
    public 

    String[] mNames=
    {
        "ball_green.png",
        "ball_red.png",
        "ball_blue.png" 
    };

    int[] mX={200,300,400};
    int[] mY={200,200,200};
    int[] mW={0,0,0};
    int[] mH={0,0,0};

    int Amount=3;
    int MyScreenWidth=512;

    int[] BitMapId={ 
        R.drawable.ball_green,  R.drawable.ball_red,
        R.drawable.ball_blue,  R.drawable.ball_green
    };

    Bitmap MyImages[];
    Rect[] mBitmapSize;

    cShapes(Context context,int screenWidth, int screenHeight)
    {
        // Load in bitmaps
        MyImages=new Bitmap[4];

        AssetManager assetManager= context.getAssets();
        InputStream inputStream;
        mBitmapSize = new Rect[Amount];
        try {
            // set scaling ratio
            float r=(float)MyScreenWidth / (float)screenWidth;
            for(int i=0;i<Amount;i++)
            {
                inputStream=assetManager.open( mNames[i]);
                MyImages[i]=BitmapFactory.decodeStream(inputStream);

                int w=(int)( (float)MyImages[i].getWidth()*r);
                int h=(int)( (float)MyImages[i].getWidth()*r);
                mBitmapSize[i]=new Rect(0,0,w,h);
                mW[i]=w; mH[i]=h;

                mX[i]=(int) ( (float)mX[i]*r);
                mY[i]=(int) ( (float)mY[i]*r);

                inputStream.close();
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }  
    }

    boolean Intersect(int id, int x,int y)
    {
        if ( x >= mX[id] && x <= mX[id]+128 && y >= mY[id] && y <= mY[id]+128 ) 
            return true;

        return false;
    }
}  // 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-14T17:04:58+00:00Added an answer on June 14, 2026 at 5:04 pm

    If i understand your question correctly, you want to access the variables defined in your super class from your sub class. If thats your question then yes, its possible using super keyword.

    class Super{
    public int i;
    }
    class Sub extends Super {
       public void method() {
        System.out.println(super.i); // you can access i as it is overriden by sub
       } 
    }
    

    Note that, you can access i directly even without the super keyword, i just included it to make it more expressive. However, you can only access i in this example when its not declared as private.

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

Sidebar

Related Questions

I want to have the parent of my class handle the event first, then
If I have child class,the child class inherits all methods from the parent,but how
In C++, is it possible to have a child class hide a base class'
I have a parent and child class that both need to implement IDisposable .
I have a parent class and child class (inherited from parent). In the child
I have a parent class Parent and a child class Child , defined thus:
Suppose I have a Base class and a Child class that inherits from Base
I have a problem. It looks like ARC synchronizes my property with child class.
I have an object that has a child collection: class Person { public string
I have a small class hierarchy where I would like to have a child

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.