© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu

Home Placements Interview Questions Java Interview Questions And Answers Java Interview Questions On Variables ▼

Java Interview Questions On Variables

1. What is a transient variable?

Ans:

A transient variable is a variable that may not be serialized.

2. If a variable is declared as private, where may the variable be accessed?

Ans:

A private variable may only be accessed within the class in which it is declared.

3. Name the eight primitive Java types

Ans:

The eight primitive types are byte, char, short, int, long, float, double, and boolean

4. What is the difference between a field variable and a local variable?

Ans:

A field variable is a variable that is declared as a member of a class. A local variable is a variable that is declared local to a method.

5. What is the difference between declaring a variable and defining a variable?

Ans:
In declaration we just mention the type of the variable and it's name. We do not initialize it. But defining means declaration + initialization. e.g String s; is just a declaration while String s = new String ("abcd"); Or String s = "abcd"; are both definitions.

6. What are the Different types of java variables?

Ans:

As you know that in Java there are two types of variables can be declared.

  • Member variables
  • Local variables.

The member variables are declared at the class level and the local variables are declared at the method level. For member variables, at the time of compilation Java compiler assigns default values depends on the type of the variable. For example for int variables the default value is 0 , for string type variables is null and char type is '\u0000' , for boolean variables is false and for object reference type is null.

7. What is mean by literal?

Ans:
A literal is value assigned to a variable. There are different types of literals depending upon the primitive data type.

Next
1 2 3 4 5 6
SLogix Student Projects
bottom