Page 1 of 1

About Question enthuware.ocajp.i.v7.2.1362 :

Posted: Sun Jun 22, 2014 4:00 pm
by Brian B
This question's answer: "synchronized keyword can never be applied to a class."

Deals with a non-access modifier that is not supposed to be covered in the OCA Java SE 7 exam.

And the option: "private keyword can never be applied to a class."

Also deals with knowledge of nested or inner classes; which are not supposed to be included on the OCA Java SE7 exam.

While I agree that it's important knowledge to have, I'd much rather focus on question similar in scope to what I'm likely to see on the exam. Is it likely that a question on non-access modifiers, aside from abstract, final, and static will be on this exam?

BTW, the explanation for why that answer is correct should include that "private, protected and public cannot be applied to a top-level class, but can be applied to an inner or nested or the answer should be "private keyword can never be applied to a top-level class" and become a viable option. Just my two cents.

Re: About Question enthuware.ocajp.i.v7.2.1362 :

Posted: Sun Jun 22, 2014 8:17 pm
by admin
1. The official exam objectives don't explicitly mention that non-access modifier are not included. Objective 1.2 says, "Define the structure of a Java class." So I don't think any modifier applicable to a class should be overlooked.

2. The explanation given with the option is, "private, protected and public can be applied to an Inner class." This is only partially correct. The correct statement should be, "private, protected and public can be applied to a nested class.".
(Corrected my statement to avoid confusion for other readers.)

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.1362 :

Posted: Sun Jun 22, 2014 10:19 pm
by Brian B
Paul,

Thanks for the clarification. I was going off of what was stated in Mala Gupta's OCA Java SE 7 certification guide(and apparently I've been misguided, so to speak).

She states the following:

"The OCA Java SE 7 Programmer I exam covers only three of these nonaccess modifiers:
abstract, final, and static...."

and

"This one shouldn’t be difficult. From the discussion of class declarations in section 1.1, you know that a top-level class can be defined only using the public or default
access modifiers....A top-level class is a class that isn’t defined within any other class. A class that is defined within another class is called a nested or inner class. Nested and inner classes aren’t on the OCA Java SE 7 Programmer I exam."

This legalistic mumbo jumbo isn't making Java much fun for me. It's hard to know which/who is correct, especially when it's coming from people who have much more experience coding in Java than I do. :D

The trouble is, I keep reading and re-reading the chapters in the guide and then I take the simulation test for the topic aligning with the chapter and get trounced by it. Any suggestions? The code in the questions seems so much harder for me to follow than the examples she presents in the guide.

Re: About Question enthuware.ocajp.i.v7.2.1362 :

Posted: Mon Jun 23, 2014 12:49 am
by admin
The topic of nested class is not on the exam but some candidates have reported getting a question on it. We have marked all the questions that deal with it with a statement that "This question may be too advanced for this exam.". This particular question hasn't been marked as such because it is more about defining a class.

Regarding the terminology top level, nested, and inner: There has been some confusion about which is which because at one time, Oracle documents called a static inner class as Top Level class.

However, your post made me go back to JLS. And here is what they now say:
A top level class is a class that is not a nested class.

A nested class is any class whose declaration occurs within the body of another class or interface.
and later on in 8.1.3
An inner class is a nested class that is not explicitly or implicitly declared static.
So it turns out that both the book and what I said earlier was not correct (a nested class is not same as inner class). I apologize for it. I saw that other questions in our question bank that referred to this aspect use the correct terminology ( 2.1315, 2.1272 ). The explanation to this particular question is also not technically wrong but is certainly incomplete. It has now been modified.

Whenever you are in doubt, you may post it here. You may also refer to the JLS, which is the final arbiter of any issue.

Coming to you other point about our questions being harder. It is true but that will only help you in the exam. You will realize that when you take the real exam. Just make sure you go through the explanation of each question.

HTH,
Paul.

Re: About Question enthuware.ocajp.i.v7.2.1362 :

Posted: Mon Oct 27, 2014 6:01 am
by Daniel Clinton
Doing test 6, this option sparked my curiousity
Option: synchronized keyword may be applied to a non-primitive variable.
Answer: Incorrect - It can only be applied to a method or a block.
I considered this option for a bit (too long!) during the exam.
Thought I'd seen synchronized followed by a reference variable
Looking it up in JLS I'm still a little unclear...

For a variable, objectRef, referencing an object

Code: Select all

synchronized (objectRef) { // some lines of code }
Is synchronized not applied to a non-primitive variable here?
(Or is the reference only to specify which object's monitor to lock?
And it is only the block to which synchronized is applied?)

Re: About Question enthuware.ocajp.i.v7.2.1362 :

Posted: Mon Oct 27, 2014 11:52 am
by admin
You are synchronizing the block. The variable objectRef is used to synchronize access to that block. Threads execute a block on code and that is why you need to synchronize a block of code. Access to a variable cannot be synchronized directly. i.e. you cannot have public synchronized MyClass myObjRef; If you want to synchronize access to a variable, you have to put it in a block i.e. synchronized(someObjectRefUsedForLocking){ myObjRef.m1(); }

Re: About Question enthuware.ocajp.i.v7.2.1362 :

Posted: Mon Feb 02, 2015 2:07 am
by gparLondon
I really struggle to answer such questions, not that I don't know the concept, it is that what is a correct answer according to the examiner, I knew that

1>Only public and default(no access specifier) is allowed for outer class, whose class name should match with file name.
2>There can be multiple class declarations within a file but only one public class is allowed whose name should match with the file name.
3>Inner class/Nested Class/Class within class, can have any access specifier.

But in one of the books I studied the same question saying "class can have any access specifier, true/false" was false according to point1 as explanation.

Similarly question like "abstract class can be instantiated true of false" is true according to some, and false according to some.

I do know that abstract classes can not be directly instantiated, but there subclasses can example:

Code: Select all

abstract  class  A{}

Code: Select all

class  test
{
  A a=new A(){};
}
Similarly this question here "enthuware.ocajp.i.v7.2.864" which seems to have all the options true/correct!!!!!

Given up hope on such questions....
GPAR

Re: About Question enthuware.ocajp.i.v7.2.1362 :

Posted: Wed Nov 23, 2016 10:01 am
by zhengye1
I saw this question in enthuware.ocajp.i.v8.2.1362, is it a little bit off topic? Since the exam topic of OCA8 doesn't have synchronized keyword...

Re: About Question enthuware.ocajp.i.v7.2.1362 :

Posted: Wed Nov 23, 2016 10:24 pm
by admin
zhengye1 wrote:I saw this question in enthuware.ocajp.i.v8.2.1362, is it a little bit off topic? Since the exam topic of OCA8 doesn't have synchronized keyword...
The official exam objectives don't explicitly mention that non-access modifier are not included. Objective 1.2 says, "Define the structure of a Java class." So I don't think any modifier applicable to a class should be overlooked.

The question is not about synchronization but just about the usage of the synchronized keyword while defining a class.

Re: About Question enthuware.ocajp.i.v7.2.1362 :

Posted: Sun Feb 19, 2017 8:08 am
by AndaRO
Please reformulate the first option.

Currently:
private keyword can never be applied to a class.

Correct:
private keyword can never be applied to a top level class.

because you said:
private, protected and public can be applied to a nested class.

The first option is confusing.

Re: About Question enthuware.ocajp.i.v7.2.1362 :

Posted: Sun Feb 19, 2017 11:56 am
by admin
AndaRO wrote:Please reformulate the first option.

Currently:
private keyword can never be applied to a class.

Correct:
private keyword can never be applied to a top level class.

because you said:
private, protected and public can be applied to a nested class.

The first option is confusing.
This option is marked as incorrect and rightly so because of the reason mentioned by you and also by the explanation. The option is actually quite clear.

Re: About Question enthuware.ocajp.i.v7.2.1362 :

Posted: Fri Feb 22, 2019 12:15 am
by OlgaAG
Option "A final variable can be hidden in a subclass."
The explanation does consider the no-final variable. I tried to hide no-final variable in IDE. It printed nothing. Why it does not printed a subclass final variable ?

public class Test {
final int c = 10;
public static void main(String[] args) {
}
}
class Test1 extends Test {
final int c = 50;
public static void main(String[] args) {
Test1 f1 = new Test1();
System.out.println(f1.c);

}
}

Re: About Question enthuware.ocajp.i.v7.2.1362 :

Posted: Fri Feb 22, 2019 1:15 am
by admin
What did it print?

Re: About Question enthuware.ocajp.i.v7.2.1362 :

Posted: Fri Feb 22, 2019 2:06 am
by OlgaAG
nothing without errors

Re: About Question enthuware.ocajp.i.v7.2.1362 :

Posted: Fri Feb 22, 2019 2:41 am
by admin
Well, then you are doing something wrong. The print statement should definitely print something, right? Unless you are trying to run Test instead of Test1.
Are you using the command line or an IDE?

Re: About Question enthuware.ocajp.i.v7.2.1362 :

Posted: Fri Feb 22, 2019 3:52 am
by OlgaAG
I tried to run Test instead of Test1 by IDE. I fixed the code and everything turned out. Thank you!

Code: Select all

 public class Test {
           final int c = 10;

           public static void main(String[] args) {
               Test1 f1 = new Test1();
               System.out.println(f1.c); }   //Output 50
       }

  class Test1 extends Test {
      final int c = 50;
        }