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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:53:53+00:00 2026-06-03T02:53:53+00:00

I am an AP Java Student and I am practicing for my exam. I

  • 0

I am an AP Java Student and I am practicing for my exam. I came across this question and I don’t understand the answer:

Consider the following classes:

public class A
{
  public A() { methodOne(); }

  public void methodOne() { System.out.print("A"); }
}

public class B extends A
{
  public B() { System.out.print("*"); }

  public void methodOne() { System.out.print("B"); }
}

What is the output when the following code is executed:

A obj = new B();

The correct answer is B*. Can someone please explain to me the sequence of method calls?

  • 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-03T02:53:55+00:00Added an answer on June 3, 2026 at 2:53 am

    The B constructor is called. The first implicit instruction of the B constructor is super() (call the default constructor of super class). So A’s constructor is called. A’s constructor calls super(), which invokes the java.lang.Object constructor, which doesn’t print anything. Then methodOne() is called. Since the object is of type B, the B’s version of methodOne is called, and B is printed. Then the B constructor continues executing, and * is printed.

    It must be noted that calling an overridable method from a constructor (like A’s constructor does) is very bad practice: it calls a method on an object which is not constructed yet.

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

Sidebar

Related Questions

I'm teaching Java EE at the university, and this was a question a student
I'm a beginning student in CS, and my classes are mostly in Java. I'm
I'm trying to calculate the average of a student's marks: import java.util.Scanner; public class
My program contains 3 classes Student , Aplt and Aplt3 classes import java.applet.Applet; import
I'm a college student doing a Java homework. I've created this program that allows
I'm an ICT student, I've gotten classes on several subjects: coding(C#, Java), webdevelopment(XHTML, CSS,
Full disclaimer: I'm a CS student, and this question is related to a recently
public class Student implements java.io.Serializable { private long studentId; private String studentName; private Set<Course>
I am a student. I learned Java during the 2nd year. Now I am
Java's Executor is (as far as I understand it) an abstraction over the ThreadPool

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.