This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

which variable/method will be called?

 
Anu satya
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,
I had been to one written test. There was two questions. Which I am not sure of correct answer.
1. which of the following variable is accessible from any class/any method at any point of time?
a)public int i;
b)protected int i;
c)private int i;
d)static int i;
e)static final int i;

I feel it must be a-public int i, Because it is public. Private can be accessed only through a object handle. And protected is only for extending class.

2. Which of the following methods can be accessed from any class at any point of time?
a)public int execute();
b)protected execute();
c)private execute();
d)static execute();
e)static final execute();

I feel it must be a-public int execute, Because it is public. Private can be accessed only through a object handle. And protected is only for extending class.

please help me
Regards,
 
vivien siu
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you got it all right it has to be public
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!