Question: What is a "Forward Reference" in java. Explain using a code.
Answer: "Forward Reference" is a way to use a variable even before its declaration.This approach is not applicable on "local variables".
example of "Forward Reference" :
class Foo
{
void aMethod()
{
// store 100 inside variable "x"
// look here, "x" is not even declared yet
x = 100;
System.out.println(x);
}
// declaration of variable "x", it is a non static variable
// it is a "Forward Reference" for variable "x"
int x;
}
=====================================================
Question: Explain System.out.println().
Answer: "System" is a class
. ("dot") is a member access operator
"out" is an object of PrintStream
"println" is a method of PrintStream
"System and PrintStream both are pre-defined-classes in Java"
Answer: "Forward Reference" is a way to use a variable even before its declaration.This approach is not applicable on "local variables".
example of "Forward Reference" :
class Foo
{
void aMethod()
{
// store 100 inside variable "x"
// look here, "x" is not even declared yet
x = 100;
System.out.println(x);
}
// declaration of variable "x", it is a non static variable
// it is a "Forward Reference" for variable "x"
int x;
}
=====================================================
Question: Explain System.out.println().
Answer: "System" is a class
. ("dot") is a member access operator
"out" is an object of PrintStream
"println" is a method of PrintStream
"System and PrintStream both are pre-defined-classes in Java"
Truly Helpful questions.. Awesome 😃
ReplyDeleteThank-you sir ,these are some points which have to be pondered
ReplyDeleteThank-you sir ,these are some points which have to be pondered
ReplyDeleteI will help for interview thanks sir.
ReplyDelete