answersLogoWhite

0

by the use of constructor . we can initialize the variables in java.The name of the constructor should be same as the name of the class .

User Avatar

Kobe Considine

Lvl 10
2y ago

Still curious? Ask our experts.

Chat with our AI personalities

RafaRafa
There's no fun in playing it safe. Why not try something a little unhinged?
Chat with Rafa
ProfessorProfessor
I will give you the most educated answer.
Chat with Professor
SteveSteve
Knowledge is a journey, you know? We'll get there.
Chat with Steve
More answers

Assuming you mean declaring a variable dynamically the way you can do with a JavaScript or Ruby eval(), it's not really possible - Java explicitly disallows eval, macros and other constructs that would let you do so.

If you just want some more key/value bindings, you could use a Map, Map keys can be generated at runtime.

User Avatar

Wiki User

15y ago
User Avatar

"Initializing" in Java or any other program for that matter is the process of setting a variable to a certain value.

Example:

int x; //Declaration

x = 5; //Initialization

String myString; //Declaration

myString = new String("Hello java initializing"); //Initialization

User Avatar

Wiki User

14y ago
User Avatar

With the assignment, i.e., the equal sign. The variable has to be declared first. Declaration and assignment can be separate:

int x;
...
x = 5;

Or they can be combined:

int x = 5;

User Avatar

Wiki User

15y ago
User Avatar

by the use of constructor . we can initialize the variables in java.The name of the constructor should be same as the name of the class .

User Avatar

Wiki User

12y ago
User Avatar

Add your answer:

Earn +20 pts
Q: How do you declare variables during run-time in java?
Write your answer...
Submit
Still have questions?
magnify glass
imp