Venkata Sai has Published 72 Answers

What is variable shadowing in java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

In Java you can declare three types of variables namely, instance variables, static variables and, local variables.Local variables − Variables defined inside methods, constructors or blocks are called local variables. The variable will be declared and initialized within the method and the variable will be destroyed when the method has ... Read More

Explain about Varargs in java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

Since JSE1.5 you can pass a variable number of values as argument to a method. These arguments are known as var args and they are represented by three dots (…)Syntaxpublic myMethod(int ... a) { // method body }ExampleIn the following example, the method named sample() accepts varargs ... Read More

What are the rules to be followed while using varargs in java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

Since JSE1.5 you can pass a variable number of values as argument to a method. These arguments are known as var args and they are represented by three dots (…)Syntaxpublic myMethod(int ... a) { // method body }Rules to follow while using varargs in JavaWe can have ... Read More

What happens when you add a double value to a String in java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

The “+” operator with a String acts as a concatenation operator.Whenever you add a String value to a double using the “+” operator, both values are concatenated resulting a String object.In-fact adding a double value to String is the easiest way to convert a double value to Strings.Exampleimport java.util.Scanner;   ... Read More

Can we use Switch statement with Strings in java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.Syntaxswitch(expression) {    case value :       // Statements       break;    case value : ... Read More

How to implement constants in java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

A constant variable is the one whose value is fixed and only one copy of it exists in the program. Once you declare a constant variable and assign value to it, you cannot change its value again throughout the program.You can create a constant in c language using the constant ... Read More

What are the rules to be followed while making a variable static and final?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

Static variables − Static variables are also known as class variables. You can declare a variable static using the keyword. Once you declare a variable static there would only be one copy of it in the class, regardless of how many objects are created from it.public static int num = ... Read More

How do we copy objects in java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

In Java you can copy an object in several ways, among them, copy constructor and the clone method are the mostly used.Using copy constructorGenerally, the copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. Java ... Read More

What are copy constructors in Java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

Generally, the copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously.Java supports for copy constructors but unlike C language, Java does not provide an explicit copy constructor you need to define it yourself.writing a copy ... Read More

Why is operator overloading not supported by java?

Venkata Sai

Venkata Sai

Updated on 30-Jul-2019 22:30:26

When a class has two or more methods by the same name but different parameters, at the time of calling based on the parameters passed respective method is called (or respective method body will be bonded with the calling line dynamically). This mechanism is known as method overloading.Operator overloadingOperator overloading ... Read More

Advertisements