I have some easy questions from the jqplus software, but need to clarify some basic
java principle concepts
QUESTION 1
Given the following set of member declarations, which of the following is true?
int a; // (1)
static int a; // (2)
int f( ) { return a; } // (3)
static int f( ) { return a; } // (4)
***************************************************************
Ans 1 and 4, cannot occur in the same class
1 and 2 cannot occur in the same class
***************************************************************
Question? what about 2 and 3, ie a static variable passed
to a non static method ? Wouldn't that give a compile
time error? If if doesn't, then in what situation do
we have a compile time error when a static variable is
passed to a non static or vice versa?
***************************************************************
QUESTION 2
What will be printed when the following program is compiled and run?
class Super
{
public int getNumber( int a)
{
return 2;
}
}
public class SubClass extends Super
{
public int getNumber( int a, char ch)
{
return 4;
}
public static void main(
String[] args)
{
System.out.println( new SubClass().getNumber(4) );
}
}
What will be printed?
***************************************************************
ans 2,
***************************************************************
Question: correct me if I am wrong but isn't the getNumber() overloaded? If not, what is the logic behind the answer to this question?
Also, assuming the getNumber()was overloaded, will it call its immediate class or the superclass of the getNumber() method
***************************************************************