I want to make a new variable with which i can do the following:
Variable v1 = 1;
Variable v2 = "Test";
Variable v3 = 7.31;
Is this possible, or is this impossible?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
If you take advantage of auto-boxing (Java SE 5.0 and later) then every one of those can be stored in an
Object(i.e. the base class of all Java types):output:
This does not necessarily make it a good idea, though!
The output shown above shows how although every variable was declared as an
Object, their real class name is one more appropriate for their type. It’s only because every class in Java is derived fromObjectthat the declarations can work that way.