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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:11:46+00:00 2026-06-13T05:11:46+00:00

Could someone explain why this works. I have 2 classes in Eclipse. A Class

  • 0

Could someone explain why this works.

I have 2 classes in Eclipse.
A Class called “Car” contains the following code..

public class Car {
    public void printOut(String variable1){
        System.out.println("Hello " +variable1);
    }
}

and another class , which is where my ‘main’ is, is called “House”, the code inside it is

import java.util.Scanner;

class House {
    public static void main(String args[]){
        Scanner input = new Scanner(System.in);
        Car carObject = new Car();

        System.out.println("Enter name here: ");
        String variable2 = input.nextLine();

        carObject.printOut(variable2);
    }
}

When I run the code, it works, it writes “Enter name here” and when I type it out, it proceeds to say “Hello “name entered” “

My question is, do ‘variable1’ and ‘variable2’ have any relation to eachother, other than that they’re both of String class.

because i’m confused as to why the code compiles correctly.

To me, it looks like variable 1 has no correlation to variable2, even though they’re both of String class, it doesn’t look like they ever interact with one another, and variable1 isn’t used in the “House” class at all, yet it still knows to compile whatever I’ve entered.
It’s as if ‘variable1’ is replaced by ‘variable2’ and whatever variable2 contains gets printed out.

  • 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-13T05:11:47+00:00Added an answer on June 13, 2026 at 5:11 am

    The method definition in class Car is sort of a prototype for when you use it. Have you ever been taught functions in maths with a ‘black box’? You put in a number, and get output. So, you enter 3, if the function is f(x) = Xx2, the output will be 6. Before you call the method, var2 is completely different from var1. In the method however, var2 is passed and replaces all var1s you use in the method. Don’t worry, I didn’t get this either when I started Java

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

Sidebar

Related Questions

Could someone help me explain this? I have two snippets of code, one works
Could someone explain to me what this portion of code means? repeat scroll 0
I'm really not getting this, so if someone could explain how this works I'd
could someone please explain this to me: I have an MVC method I want
Could someone explain this for me? I have standard relations in my MSSQL DB:
I ran across this and was wondering if someone could explain why this works
Could someone please help explain why I can't get this to work? I properly
Could someone explain this (strange) behavior? Why is the length in the first example
Could someone please explain this weird phenomenon: http://jsfiddle.net/sPA2V/ For some reason, the box footer
int64_t maskTestNum = (1ll << 63); could someone explain why this prints as the

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.