• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Can you always modify a public field?

 
Greenhorn
Posts: 16
1
Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone!

I came across this question in K&B 7. The question is simply "Which are true?", and one the choices says "A public field can be accessed and modified from anywhere." It is supposed to be correct but I don't agree. What if a public filed also has a final modifier? Then even you can access it from anywhere but you cannot modify it.

What do you guys think?

Cheers

Zhifu
 
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you specify some more details about the question? chapter, page, question number? Because I tried to track it down, but without success.

A public field can indeed be accessed from anywhere and can also be modified from anywhere unless it is marked final. So you are correct and it might be considered another errata item. Therefore the requested info is nice to know
 
Zhifu Ge
Greenhorn
Posts: 16
1
Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:Can you specify some more details about the question? chapter, page, question number? Because I tried to track it down, but without success.

A public field can indeed be accessed from anywhere and can also be modified from anywhere unless it is marked final. So you are correct and it might be considered another errata item. Therefore the requested info is nice to know



Hi, it's from OCA Test 2 in the CD-ROM, it's number 7 but I think the number may be randomized. Here is the screenshot:

Screen-Shot-2014-11-10-at-7.01.40-PM.png
[Thumbnail for Screen-Shot-2014-11-10-at-7.01.40-PM.png]
 
author & internet detective
Posts: 42134
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are correct that a final field would be an exception. If the question considers "final", no answers would be correct, right? That would be a clue.

Also, remember that the real exam tells you how many questions are correct. Which means you can figure out about edge case answers that way.
 
Zhifu Ge
Greenhorn
Posts: 16
1
Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:You are correct that a final field would be an exception. If the question considers "final", no answers would be correct, right? That would be a clue.



First, I think we are supposed to evaluate each choice independently. Secondly, even if a final filed is assumed for every choice, C and E will still be correct.

Jeanne Boyarsky wrote:Also, remember that the real exam tells you how many questions are correct. Which means you can figure out about edge case answers that way.



Really? Are you sure? That would be awesome!
 
Jeanne Boyarsky
author & internet detective
Posts: 42134
937
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zhifu Ge wrote:

Jeanne Boyarsky wrote:Also, remember that the real exam tells you how many questions are correct. Which means you can figure out about edge case answers that way.



Really? Are you sure? That would be awesome!


I should have said "how many answers" are correct (not how many questions). But yes, I am sure. It's been true on past exams and was still the case on the beta for Java 8 as well.
 
Zhifu Ge
Greenhorn
Posts: 16
1
Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:

Zhifu Ge wrote:

Jeanne Boyarsky wrote:Also, remember that the real exam tells you how many questions are correct. Which means you can figure out about edge case answers that way.



Really? Are you sure? That would be awesome!


I should have said "how many answers" are correct (not how many questions). But yes, I am sure. It's been true on past exams and was still the case on the beta for Java 8 as well.



That is fantastic news for me. I am going to take OCAJP 7 on Thursday.
 
Roel De Nijs
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zhifu Ge wrote:Hi, it's from OCA Test 2 in the CD-ROM, it's number 7 but I think the number may be randomized.


That explains why I couldn't locate the question. I didn't check the mock tests on the cd-rom

Zhifu Ge wrote:

Jeanne Boyarsky wrote:You are correct that a final field would be an exception. If the question considers "final", no answers would be correct, right? That would be a clue.



First, I think we are supposed to evaluate each choice independently. Secondly, even if a final filed is assumed for every choice, C and E will still be correct.


True! The best thing you can do is evaluate each choice seperately and tell yourself why this choice is correct/incorrect. But there mostly is some context in the question. None of the choices mention the final keyword, but public, protected and private is mentioned so it's probably about the visibility. In some choices instance and static is used, so probably testing that knowledge as well. If they were testing your knowledge about final, you would probably see soms choices where "a final variable" and "a non-final variable" are used.

Zhifu Ge wrote:

Jeanne Boyarsky wrote:Also, remember that the real exam tells you how many questions are correct. Which means you can figure out about edge case answers that way.



Really? Are you sure? That would be awesome!


I have taken 3 ocpjp exams and all of them mentioned the number of correct answers. And other ranchers taking the exam didn't have mentioned another exam format. So it definitely still applies! Therefore K&B7 will probably be (a little) harder than the actual exam. You don't know how many answers you need to select in the mock questions/exams, so you are required to evaluate all of them. On the exam you know exactly how many choices you must select. So even if you don't have a clue at all, you have a (small) chance to have this question correct and score 1 point

Hope it helps!
Good luck Thursday with your exam!
 
Zhifu Ge
Greenhorn
Posts: 16
1
Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have taken 3 ocpjp exams and all of them mentioned the number of correct answers. And other ranchers taking the exam didn't have mentioned another exam format. So it definitely still applies! Therefore K&B7 will probably be (a little) harder than the actual exam. You don't know how many answers you need to select in the mock questions/exams, so you are required to evaluate all of them. On the exam you know exactly how many choices you must select. So even if you don't have a clue at all, you have a (small) chance to have this question correct and score 1 point



Thank you for this information. I really like it when we know how many correct options to choose.

On a side topic, I am curious why one would take the OCPJP exam more than once. I assume you are really good with Java and must have passed with flying colors on the first try.

Hope it helps!
Good luck Thursday with your exam!



Boy! You guys are so nice! The user agreement really works!(if you know what I mean)

I have done 3 Enthuware mock tests and scored an average of 75% or so. But I find the time is just enough. I don't feel comfortable enough so I have rescheduled my test to next Monday.
 
Roel De Nijs
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zhifu Ge wrote:On a side topic, I am curious why one would take the OCPJP exam more than once. I assume you are really good with Java and must have passed with flying colors on the first try.


Because these were all different Java versions. And with different Java versions you (almost) always have extra features, new syntax,... For example Java 5 had amongst onther things the enhanced for loop, enums and generics. Java 6 had almost nothing new (except for Console, NavigableMap & NavigableSet). Java 7 has a bunch of new things (as you know): multi-catch, try-with-resources, nio2.0,... (and also some new objectives are added to the exam itself: jdbc, concurrency api,...). In Java 8 you'll have lambdas, streams, collectors and so on.
Another reason: while you prepare for these exams, your knowledge is kept up-to-date and refreshed every time, so your knowledge remains fresh in your memory. And that's very useful of course, and even more when you need to coach some team members (then you don't have the time to quickly google ). This is also one of the reasons why I do sometimes a technical review of a study guide (like with K&B7 ), although the main reason for that is just that I like to nitpick
And finally: I'm just one of these guys who liked (high) school, learning and taking exams

Zhifu Ge wrote:I don't feel comfortable enough so I have rescheduled my test to next Monday.


That's a very wise decision! Only take the exam when you feel comfortable.
 
Zhifu Ge
Greenhorn
Posts: 16
1
Mac Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:

Zhifu Ge wrote:On a side topic, I am curious why one would take the OCPJP exam more than once. I assume you are really good with Java and must have passed with flying colors on the first try.


Because these were all different Java versions. And with different Java versions you (almost) always have extra features, new syntax,... For example Java 5 had amongst onther things the enhanced for loop, enums and generics. Java 6 had almost nothing new (except for Console, NavigableMap & NavigableSet). Java 7 has a bunch of new things (as you know): multi-catch, try-with-resources, nio2.0,... (and also some new objectives are added to the exam itself: jdbc, concurrency api,...). In Java 8 you'll have lambdas, streams, collectors and so on.
Another reason: while you prepare for these exams, your knowledge is kept up-to-date and refreshed every time, so your knowledge remains fresh in your memory. And that's very useful of course, and even more when you need to coach some team members (then you don't have the time to quickly google ). This is also one of the reasons why I do sometimes a technical review of a study guide (like with K&B7 ), although the main reason for that is just that I like to nitpick
And finally: I'm just one of these guys who liked (high) school, learning and taking exams

Zhifu Ge wrote:I don't feel comfortable enough so I have rescheduled my test to next Monday.


That's a very wise decision! Only take the exam when you feel comfortable.



I passed the test

I have posted my experience here: https://coderanch.com/t/642958/sr/certification/Brand-OCAJP-shares-experience

I can help with others now. You guys helped me a lot. I have to give something back.
 
Roel De Nijs
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Zhifu Ge wrote:I can help with others now. You guys helped me a lot. I have to give something back.


You are more than welcome to answer some posts here on the CodeRanch! And having a certificate wasn't a prerequisite

You have already helped many ranchers by posting such detailed experience. Keep up the good work!
 
Ranch Hand
Posts: 40
2
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, sorry for bring up an older post. Congratulations on passing. I'm preparing right now for OCA 7.

Not only is the field not allowed to be final, it should also be in a class that is accessible. The statement simply isn't true when the field is in class with default ( package-private) access. Or even worse within a private nested or anonymous class but these aren't on the OCA exam.

I wonder if
1. I'm thinking too deeply now
2. What should I do if I encounter this question on the actual exam, or won't that happen?
 
Roel De Nijs
Sheriff
Posts: 11606
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Henno Vermeulen wrote:I wonder if
1. I'm thinking too deeply now
2. What should I do if I encounter this question on the actual exam, or won't that happen?


This topic discusses the exact same answer of the exact same question in great detail and provides some useful information about how you should handle this kind of question/answer on the actual exam.

Hope it helps!
Kind regards,
Roel
 
Henno Vermeulen
Ranch Hand
Posts: 40
2
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Roel De Nijs wrote:
This topic discusses the exact same answer of the exact same question in great detail and provides some useful information about how you should handle this kind of question/answer on the actual exam.

Hope it helps!
Kind regards,
Roel


Wow it certainly handles my question elaborately. Thank you very much!
 
reply
    Bookmark Topic Watch Topic
  • New Topic