answersLogoWhite

0

Java allows us to perform 'dynamic initialization' of variables too.

What this means is that you can initialize variables using expressions (as will be seen in the example).

In the program, we have a int variable 'root' which has an initial defined value of 10. We then create another variable 'square' of the same data-type, which will store the square of root.

//This program displays dynamic initialization in java

publicclassExample

{

publicstaticvoidmain(String args[])

{

introot=10; //root has a constant value assigned

intsquare=root*root; //notice that square has "root*root" assigned to it

//if u change the value of root,

//the value of square changes accordingly

//after each compilation

//display the values of square and root

System.out.println("Root= " +root + " Square= "+square);

}

}

User Avatar

Wiki User

12y ago

What else can I help you with?

Continue Learning about Engineering

How do you initialize an array variable in java program?

An array in java is a collection of items stored into a single unit. The array has some number of slots (elements), each slot in the array can hold an object or a primitive value. Arrays in java are objects that can be treated just like other objects in the languageArrays can contain any type of element value , but we can't store different types in a single array. We can have an array of integers or an array of strings or an array of arrays.To create an array in java ,use three steps1. Declare a variable to hold the array2. Create a new array object and assign it to the array variable3. Store things in that array


What is the use of Constructor with Dynamic allocation?

Constructors are necessary to initialize classes. It allows to avoid to a lot of problems with unauthorized access of memory. Dynamic allocation makes possible allocation of memory during execution of program. If you do not use dynamic allocation, all required memory will be allocated during initialization phase (constructors are usually responsible for that). But you can't use more memory. Dynamic allocation was designed to overcome such problems.


What is dynamic method dispatch in java?

Dynamic Method Dispatch in Java is when a method call is resolved at runtime based on the actual object the reference points to. For example, if a parent class has a method and a child class overrides it, a parent reference pointing to a child object will execute the child’s version of the method. This allows Java to decide which method to run during execution, enabling runtime polymorphism. To dive deeper into this topic, visit the Uncodemy blog for detailed insights.


What is an initialization statement?

When a declared variable receives a value to hold. i.e. int lalalala; lalalala = 0; //initialization of lalalala


What is lazy initialization?

Lazy initialization is a process by which an object is not initialized until it is first called in your code. The .NET 4.0 introduces a new wrapper class, System.Lazy<T>, for executing the lazy initialization in your application. Lazy initialization helps you to reduce the wastage of resources and memory requirements to improve performance. It also supports thread-safety.

Related Questions

How is dynamic initialization of objects is achieved?

by creating class as an static class


What is need to build dynamic web documents?

java,html


What is the basic of java?

java buzzwords like simple , Secure , Portable, Object-Oriented, Robust, Dynamic, etc............


How garbage collector works on anonymous class in java?

about the garbage collector it is in java and it is mainly responsible for dynamic memory manegement


What is dynamic binding in java?

Dynamic Binding means declaring variables at run time only rather than declaring it at compile time.


How do you initialize an array variable in java program?

An array in java is a collection of items stored into a single unit. The array has some number of slots (elements), each slot in the array can hold an object or a primitive value. Arrays in java are objects that can be treated just like other objects in the languageArrays can contain any type of element value , but we can't store different types in a single array. We can have an array of integers or an array of strings or an array of arrays.To create an array in java ,use three steps1. Declare a variable to hold the array2. Create a new array object and assign it to the array variable3. Store things in that array


What is the use of Constructor with Dynamic allocation?

Constructors are necessary to initialize classes. It allows to avoid to a lot of problems with unauthorized access of memory. Dynamic allocation makes possible allocation of memory during execution of program. If you do not use dynamic allocation, all required memory will be allocated during initialization phase (constructors are usually responsible for that). But you can't use more memory. Dynamic allocation was designed to overcome such problems.


The procedure entry point security initialization qqrv could not be located in the dynamic link library ntrtl60bpl?

For my case which I can not explain though, Changing run time package will fix this problem Terry G.


What is dynamic method dispatch in java?

Dynamic Method Dispatch in Java is when a method call is resolved at runtime based on the actual object the reference points to. For example, if a parent class has a method and a child class overrides it, a parent reference pointing to a child object will execute the child’s version of the method. This allows Java to decide which method to run during execution, enabling runtime polymorphism. To dive deeper into this topic, visit the Uncodemy blog for detailed insights.


What is buzz word in java define?

the Java 'white paper" buzzwords: simple object oriented network savvy robust secure architecture neutral portable interpreted hight performance multithreaded dynamic


What is java web development?

A Java web application is a collection of dynamic resources (such as Servlets, JavaServer Pages, Java classes and jars) and static resources (HTML pages and pictures). A Java web application can be deployed as a WAR (Web Archive) file. A WARfile is a zip file which contains the complete content of the corresponding web application.


What is an initialization statement?

When a declared variable receives a value to hold. i.e. int lalalala; lalalala = 0; //initialization of lalalala