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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:23:04+00:00 2026-06-13T10:23:04+00:00

package main; class F { void f() { System.out.print(F.f() ); this.g(); } void g()

  • 0
package main;

class F {
    void f() {
        System.out.print("F.f() ");
        this.g();
    }

    void g() {
        System.out.print("F.g() ");
    }
}

class Fbis extends F {
    void f() {
        System.out.print("Fbis.f() ");
        this.g();
    }

    void g() {
        System.out.print("Fbis.g() ");
        super.f();
    }
}

public class Main {
    public static void main(String[] args) {
        F f = new Fbis();
        ((F) f).f();
    }
}

Hi, I’m trying to understand why the g() function in the F class is never called.
This code compiles and runs but leads to an infinite loop that show this:

Fbis.f() Fbis.g() F.f() Fbis.g() F.f() Fbis.g() F.f() Fbis.g() F.f() Fbis.g() F.f() Fbis.g() F.f() Fbis.g() F.f() Fbis.g() F.f() ...

So what happens, is that Fbis.f is called, which calls Fbis.g, which calls F.f but instead of calling F.g, F.f calls Fbis.g.

  • 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-13T10:23:05+00:00Added an answer on June 13, 2026 at 10:23 am

    Basically, that is how inheritance works. The Fbis class overrides the g() method so for any instance of Fbis calling g() will run the code from the Fbis class, even if this called from within the F class itself.

    This is usually desirable behaviour. For example, imagine a delete() method. In a parent class this does some clean up when the object is deleted by your application. In the child class it does extra clean-up specific for this child. You would want the extra clean up to be done whenever delete() was called, even if this was from within the parent class.

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

Sidebar

Related Questions

package GC; import java.util.Scanner; public class main { public static void main(String args[]) {
package org.study.algos; public class Study { public static void main(String[] args) { A a
package pack; public class sample{ public static void main(String input[]) { NumberFormat numberFormat =
Java code: package library; import java.nio.ByteBuffer; public class Library { static{System.loadLibrary(TestDLL);} native static void
I have this code: package picalculator; //import java.util.Scanner; public class PiCalculator { static int
Here's the code: package testpack; import java.io.*; public class InputStreamReadDemo { private void readByte()
This is what I have so far. package testproject; public class Combinations{ public Combinations(){
So I have this code : package Firstpack; import java.io.*; import java.util.*; public class
I want to run the constructor of the Main.class in the package Test2, located
This program returns: package main import ( flag fmt ) func main() { num_agents

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.