Jump to content

Java Program

Featured Replies

Is it possible for Java to have two different variables named "number" and "Number?"

You will be able to determine the answer by writing a small test program that compares the two variables.

 

Psuedo-ish code:

 

Main {

int Number = 10

int number = 5 //if Java recognizes N and n as different variables then you will get no error, otherwise you may get an error here.

 

//review output. if Number and number output is the same as what you initially declared then Java recognizes upper and lower case names as different vars.

printf("Number: ", Number, " number ", number )

}

A general tip - it's been helpful to me when learning a new language to answer these type of questions using similar small test programs.

... but note it's a very bad idea, unless part of a clearly understood naming convention.

 

For example, you might have a property named "Number" (e.g. name all properties with leading capital), and a method in the same class might have a locally scoped (meaning "visible" only inside that method) variable named "number". (This could still be a bad idea, depending on context).

 

But you definitely wouldn't want a method that has both "Number" and "number" as locally scoped variables, or a class with both of those as properties - too easily mixed up.

 

 

(Not a criticism of the preceeding example by Curiatron, which was only for illustration.)

Edited by pzkpfw

Archived

This topic is now archived and is closed to further replies.

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.