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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:13:07+00:00 2026-05-27T15:13:07+00:00

I’m new to Java and to OOP, so some things below may sound silly,

  • 0

I’m new to Java and to OOP, so some things below may sound silly, but…

I understand a situation when i have two classes (two different types) and one does whatever it wants with the instance of the other one, like

class A { ... }

class B { 
   ...
   public A someMethod() { 
      return new A;
   }
   ...
}

At the point when B’s method is declaring some code to work with A, the A type is pretty defined and complete and thus one thing can use/make something with another. That all is pretty logical for me at this point.

But I was thinking about the case when a class declaration has a method in it that works with the instance of its own type. How that is possible? I would probably imagine some ‘loop’, but it’s not a loop. How the method can have a code about something that is not ‘complete’ or completely known at the moment when the code is being written.

Sorry if i made some muddled description, I just couldn’t find better words to explain this. Absolutely can’t fit this concept into my head. Could somebody please explain?

UPDATE: i found some snippet that may help you to understand my problem. The code in the class below does not create instance of itself, but it casts the absolutely other object to the its (RectanglePlus’) type…

public class RectanglePlus 
    implements Relatable {
    ...

    // four constructors
    public RectanglePlus() {
        origin = new Point(0, 0);
    }
    ...
    // a method required to implement
    // the Relatable interface
    public int isLargerThan(Relatable other) {
        RectanglePlus otherRect 
            = (RectanglePlus)other;
        if (this.getArea() < otherRect.getArea())
            return -1;
        else if (this.getArea() > otherRect.getArea())
            return 1;
        else
            return 0;               
    }
}

Copyright © 2008, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.

  • 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-27T15:13:08+00:00Added an answer on May 27, 2026 at 3:13 pm

    During compilation, this is done by having a multi-pass compiler that first analyzes class and method signatures before dealing with individual statements.

    During runtime, class loading and initialization happens when the class is first used and usually before any of its code is executed. Thus, when a method of the class is executed, its
    entire structure and code have been initialized.

    But you are right that things can get muddled with code that is executed during class initialization, such as static initializer blocks and initial assignments to static fields. If these call methods of the class, such methods are executed within a not-yet fully initialized class context, which can cause unexpected behaviour.

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have thousands of HTML files to process using Groovy/Java and I need to
I have some data like this: 1 2 3 4 5 9 2 6
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

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.