Please open the menu to show more

Sunday, August 6, 2017

Frequently asked question asked by good companies on java programming language part-4

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"


4 comments:

  1. Truly Helpful questions.. Awesome 😃

    ReplyDelete
  2. Thank-you sir ,these are some points which have to be pondered

    ReplyDelete
  3. Thank-you sir ,these are some points which have to be pondered

    ReplyDelete
  4. I will help for interview thanks sir.

    ReplyDelete