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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:47:19+00:00 2026-06-13T18:47:19+00:00

The way my teacher writes and organizes code is very different than what is

  • 0

The way my teacher writes and organizes code is very different than what is proposed in my supplementary textbook. In a recent lab, we were required to use the wheels library to display several objects in a single window. Here is the Snowman class that was written by my teacher (code for other objects have not been included for convenience):

public class Snowman {
    private Ellipse _top;
    private Ellipse _middle;
    private Ellipse _bottom;

public Snowman() {
        _top = new Ellipse();
        _top.setColor(Color.WHITE);
        _top.setFrameColor(Color.BLACK);
        _top.setFrameThickness(1);
        _top.setSize(80, 80);
        _middle = new Ellipse();
        _middle.setColor(Color.WHITE);
        _middle.setFrameColor(Color.BLACK);
        _middle.setFrameThickness(1);
        _middle.setSize(120, 120);
        _bottom = new Ellipse();
        _bottom.setColor(Color.WHITE);
        _bottom.setFrameColor(Color.BLACK);
        _bottom.setFrameThickness(1);
        _bottom.setSize(160, 160);
    }
    public void setLocation(int x, int y) {
        _top.setLocation(x + 40, y - 170);
        _middle.setLocation(x + 20, y - 100);
        _bottom.setLocation(x, y);
    }
}    

This object, among others, is later instantiated in the SnowmanCartoon class:

public class SnowmanCartoon extends Frame{
    private Snowman _snowman;
    private Eyes _eyes;
    private Hat _hat;
    private Bubble _bubble;

    public SnowmanCartoon() {
        _snowman = new Snowman();
        _snowman.setLocation(100, 300);
        _eyes = new Eyes();
        _eyes.setLocation(165, 150);        
        _hat = new Hat();
        _hat.setLocation(152, 98);
        _bubble = new Bubble();
        _bubble.setLocation(280, 60);
    }
    public static void main(String[] args) {
        new SnowmanCartoon();
    }
}

Here are my concerns:

  1. In both of these classes, why is there a method of the same name as the class, and what is its purpose?

  2. Why is the method setLocation() a void method while the method Snowman() is not, even though Snowman() does not return anything?

  3. In the SnowmanCartoon class, when it says private Snowman _snowman; and _snowman = new Snowman();, is Snowman referring to the Snowman class, or rather the Snowman() method?

  4. If the instantiation of the Snowman object is referring to the Snowman() method to set all of its properties, why don’t I need to use the dot operator: Snowman.Snowman()?

  5. In my textbook, instance variables and methods are declared in a one class and are instantiated in another. However, they seem to occur simultaneously in my teacher’s code.

  • 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-13T18:47:20+00:00Added an answer on June 13, 2026 at 6:47 pm

    The method that is named the same as a class is called “constructor” of the class. It is used to instantiate an object.

    Example:

    public class MyClass { // class
        public MyClass() { // constructor
    
        }
    }
    

    Note that constructor is just like any other method, however, it does not have a return type. It basically returns “this” object.

    When you call

    MyClass a = new MyClass(); 
    

    this will actually invoke the constructor and create the object.

    Note that you can have multiple constructors in a class by using different number and types of parameters.

    In java, if you do not include any constructor, then any class will by default have the default parameterless constructor.

    public MyClass() {
    }
    

    Tons of information available on constructors online. They are the basic concepts to start learning object oriented programming. Some more information here.

    –EDIT–
    answering question about how to call specific question.

    Take these two constructors

    public MyClass(){
    // do things
    }
    
    public MyClass(String p){
    // do things
    }
    

    Then when you instantiate object

    MyClass c = new MyClass(); // use constructor 1
    MyClass d = new MyClass("value"); // use constructor 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A way to get HTTP_REFERER , We can use document.referrer in browser side javascript
I recently saw some code from a college teacher where he had something like
I want to know which is better way for this problem: A teacher can
I know There are different way of reprentation for Conversion of Association,Aggregation and composition
I have an assignment that my teacher has told us to use this in
I try to use This Way to fire a custom validator in client side
What is the best way to model the following kind of relationship in Code
I have some AS3 MP3 code that my teacher gave me a while ago
Is there a way I exclude one teacher (Robert) from the list in this
Any way to realize emacs keybind on Qt Creator (QTC)? Some possibilities: emacskeys but

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.