This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes anyone could explain this? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "anyone could explain this?" Watch "anyone could explain this?" New topic
Author

anyone could explain this?

M Mistroni
Ranch Hand

Joined: Oct 03, 2005
Posts: 62
hello,
ind oing a mock exam i found this

# A class variable is declared using following modifiers

1. protected
2. private
3. public
4. static

i answered, 4 .. exam said correct answers were 1 and 4..

my assumption is that the mock examis injcorrect..

any comments?

regards
marco
Kashyap Hosdurga
Ranch Hand

Joined: Sep 19, 2005
Posts: 90
Is this what you are asking?


class abc {
public int x=1;
private int y=2;
static int z=3;
protected int w=4;
public void gety() {
System.out.println("y="+y);
}
}
class xyz {
public static void main(String args[]) {
abc i = new abc();
System.out.println("x="+i.x);
i.gety();
System.out.println("z="+i.z);
System.out.println("w="+i.w);
}
}
[ April 20, 2006: Message edited by: Kashyap Hosdurga ]
Vishal Chawla
Greenhorn

Joined: Apr 06, 2006
Posts: 28
Frankly,
it can be any combination of 1 & 4 , 2&4, 3 & 4, but 4 is the one that is required, so in short, i agree
bnkiran kumar
Ranch Hand

Joined: Mar 02, 2006
Posts: 176
Mistroni
A static variable can be public,private or protected there is no problem in that.

If you are asking about classes, outer class can be public or with default access specifier but inner classes can be public or protected or private or with default access specifier,static.


Kiran Kumar.
bnkiran kumar
Ranch Hand

Joined: Mar 02, 2006
Posts: 176
but static is not mandatory for inner classes, so i think question is wrong
Shaliey Gowtham
Ranch Hand

Joined: Mar 20, 2006
Posts: 104
But kiran static is required for the variable to be at class level
Inner classes doesn't allow the use of static, except for final primitives and Strings.
bnkiran kumar
Ranch Hand

Joined: Mar 02, 2006
Posts: 176
Gowtham
i am telling like this,

class Kiran
{
static public class Gowtham
{
}
}
bnkiran kumar
Ranch Hand

Joined: Mar 02, 2006
Posts: 176
which can also be
class Kiran
{
public class Gwotham
{
}
}
so i said static is not madatory, for static variables it is necessary.
Shaliey Gowtham
Ranch Hand

Joined: Mar 20, 2006
Posts: 104
Even for the inner class you require a instance of an outer class to access so its not at class level.
But for top level nested class you can access it without an instance of the outer class.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: anyone could explain this?