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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:35:57+00:00 2026-05-16T11:35:57+00:00

For school I need to learn Java and since I’m used to C++ (like

  • 0

For school I need to learn Java and since I’m used to C++ (like Cocoa/Objective-C) based languages, I get really frustrated on Java.

I’ve made a super-class (that can also be used as a base-class):

public class CellView {
    public CellViewHelper helper; // CellViewHelper is just an example

    public CellView() {
        this.helper = new CellViewHelper();
        this.helper.someVariable = <anything>;

        System.out.println("CellView_constructor");
    }
    
    public void draw() {
        System.out.println("CellView_draw");
    }

    public void needsRedraw() {
        this.draw();
    }

}

public class ImageCellView extends CellView {

    public Image someImage;

    public ImageCellView() {
        super();
        this.someImage = new Image();
        System.out.println("ImageCellView_constructor");
    }

    public void setSomeParam() {
        this.needsRedraw(); // cannot be replaced by this.draw(); since it's some more complicated.
    }

    @Override public void draw() {
        super.draw();
        System.out.println("ImageCellView_draw");
    }

}

Now, when I call it like this:

ImageCellView imageCellView = new ImageCellView();
imageCellView.setSomeParam();

I get this:

CellView_constructor

ImageCellView_constructor

CellView_draw

However, I want it to be:

CellView_constructor

ImageCellView_constructor

CellView_draw

ImageCellView_draw

How can I do this?

Thanks in advance,

Tim

EDIT:

I also implemented this method to CellView:

public void needsRedraw() {
    this.draw();
}

And this to ImageCellView:

public void setSomeParam() {
    this.needsRedraw(); // cannot be replaced by this.draw(); since it's some more complicated.
}

And I’ve been calling this:

ImageCellView imageCellView = new ImageCellView();
imageCellView.setSomeParam();

Does this causes the problem (when I call a function from the super it calls to the super only)? How can I solve this… (without having to redefine/override the needsRedraw()-method in every subclass?)

  • 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-16T11:35:58+00:00Added an answer on May 16, 2026 at 11:35 am

    You should get proper output.

    I tried you example just commented unrelated things:

    import java.awt.Image;
    
    public class CellView {
        //public CellViewHelper helper; // CellViewHelper is just an example
    
        public CellView() {
            //this.helper = new CellViewHelper();
            //this.helper.someVariable = <anything>;
    
            System.out.println("CellView_constructor");
        }
    
        public void draw() {
            System.out.println("CellView_draw");
        }
    
        public static void main(String[] args) {
            ImageCellView imageCellView = new ImageCellView();
            imageCellView.draw();
        }
    }
    
    class ImageCellView extends CellView {
    
        public Image someImage;
    
        public ImageCellView() {
            super();
            //this.someImage = new Image();
            System.out.println("ImageCellView_constructor");
        }
    
        @Override public void draw() {
            super.draw();
            System.out.println("ImageCellView_draw");
        }
    
    }
    

    and I get following output:

    CellView_constructor

    ImageCellView_constructor

    CellView_draw

    ImageCellView_draw

    This is exactly what you want, and this is what your code print’s.

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

Sidebar

Related Questions

I have a class with fields like firstname, age, school etc. I need to
Even if I'm not new to Java, I've only used it in school/university environment
I'm currently building a console app for a school project and I really need
For school I need to make a game dealing [X] random cards. I used
Iam doing a school assignment in Java, and I need some help to do
Guys, I need to find a good site like codingbat to learn again C++.
I need to draw a graph like bus station schema: o-School----o-Church-------o-Police . So, simple
In a project for school I need to send xml data to the client
For a school project I need to create a program and it'd be nice
For a school project i need to write or use a online programming editor.

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.