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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:16:38+00:00 2026-06-06T17:16:38+00:00

I’m a beginner in Java, I used PHP, C++ and Lua and never had

  • 0

I’m a beginner in Java, I used PHP, C++ and Lua and never had this problem, I made two classes just for exercising’s sake Facto and MyFacto, first one does find a factorial and the second one should find factorial not by adding, but by multiplying. Don’t blame me for the stupid and pointless code, I am just testing and trying to get the hang of Java.

Main:

public class HelloWorld {
public static void main(String[] args) {

    Facto fc = new Facto(5);
    fc.calc();
    System.out.println(fc.get());   

    MyFacto mfc = new MyFacto(5);
    mfc.calc();
    System.out.println(mfc.get());

}
}

Facto.java:

public class Facto {
private int i;
private int res;

public Facto(int i) {
    this.i = i;
}

public void set(int i) {
    this.i = i;
}

public int get() {
    return this.res;
}

public void calc() {
    this.res = this.run(this.i);
}

private int run(int x) {
    int temp = 0;
    if(x>0) {
        temp = x + this.run(x-1);
    }
    return temp;
}
}

MyFacto.java:

public class MyFacto extends Facto {
public MyFacto(int i) {
    super(i);
}

private int run(int x) {
    int temp = 0;
    if(x>0) {
        temp = x * this.run(x-1);
    }
    return temp;
}
}

I thought the result should be 15 and 120, but I get 15 and 15. Why is that happening? Does it have something to do with calc() method not being overriden and it uses the run() method from the Facto class? How can I fix this or what is the right way to override something like this?

  • 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-06T17:16:40+00:00Added an answer on June 6, 2026 at 5:16 pm

    The reason you’re running into issues is due to member access visibility.

    In a nutshell:

    • public allows any Java class to see the field/function, so long as it can be reached.
    • <package>, or no apparent modifier, allows any Java object (but not subclasses) to see the field/function, as long as they’re in the same directory, or package.
    • protected allows the declared class and all other subclasses to access that field/function, as well as any class in the same directory/package.
    • private allows only the declared class to access that field/function.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.