Variables and Data Types
Variables and Data Types
Only one copy of each class variable is created, regardless of how many
objects are created from it.
ClassName.VariableName
Static variables are created with the start of execution of a
program and destroyed when the program terminates.
class VariableDemo
{
public static void main(String [] rk)
{
public int x = 10;
System.out.print(x);
}
}
Brainstorming 2
What will be the output of the following Program?
class VariableDemo
{
static int x;
public static void main(String [] rk)
{
int x;
System.out.print(x);
}
}
Brainstorming 3
What will be the output of the following Program?
class VariableDemo
{
static int x;
public static void main(String [] rk)
{
int x;
System.out.print(VariableDemo.x);
}
}
• Which of the following is INCORRECT header
for the main method in java?
}
print()
• print() method in Java is used to display a
text on the console. This text is passed as the
parameter to this method in the form of
String.
• This method prints the text on the console
and the cursor remains at the end of the text
at the console. The next printing takes place
from just here.
• void print(boolean b) – Prints a boolean
value.
• void print(char c) – Prints a character.
• void print(char[] s) – Prints an array of
characters.
• void print(double d) – Prints a double-precision
floating-point number.
• void print(float f) – Prints a floating-point
number.
• void print(int i) – Prints an integer.
• void print(long l) – Prints a long integer.
• void print(Object obj) – Prints an object.
• void print(String s) – Prints a string.
println()
char 16 0 to 65,536