Ask a Question
Send an email to me.
 
Java Question and Answer Forums
JavaRanch Big Moose Saloon
Marcus Green's Discussion Forum
java.sun.com Forums, Chat and User Groups
 
Other Resources
Java Language Specification
Java Virtual Machine Specification
Java 2 Platform, Standard Edition, v 1.4.0 API Specification
 
Tutorials
Learning the Java Language
Operator Precedence Chart, Expressions, Statements, Blocks
Programming with Assertions
 
Answers: Certified Java Programmer Mock Exam
No.AnswerRemark
1Compile-time error  The access modifiers public, protected and private, can not be applied to variables declared inside methods.  
2Prints: 0  Member variables are initialized automatically. Type int variables are initialized to zero.  
3Prints: 1, 1, 0, 1  Both instances of class Red share a single copy of the static field b. Although field b is only incremented using the r1 reference, the change is visible in the r2 instance of class Red.  
4Compile-time error  A static method can not access a non-static variable.  
5b  c  d  e  final  private  protected  public  The access modifiers, private, protected and public, can be applied to a field. A final field can not have its value assigned more than once. The abstract modifier may be applied to methods but not to fields.  
6a  c  d  static  transient  volatile  A transient field is not part of the persistent state of an object. Transient fields are not serialized. Fields that are shared between threads may be marked volatile to force each thread to reconcile its own working copy of the field with the master copy stored in the main memory. The synchronized modifier may be applied to methods but not to fields.  
7transient  A transient field is not part of the persistent state of an object, so it is not serialized. A static field is also not part of the persistent state of an object, and also is not serialized.  
8a  d  e  A value can not be assigned to a final field more than once.  A compile-time error is thrown if a blank final instance variable is not assigned a value before the end of each constructor.  A field can not be declared both final and volatile Static and non-static field variables may be declared final. All final fields must be definitely assigned a value once and only once. If the declaration of a final variable does not include an initializer then the variable is called a blank final. All blank, final, static variables must be assigned in a static initializer. All blank final non-static variables must be assigned by the end of the instance construction process. A field is sometimes shared between threads. The volatile modifier is used to force threads to reconcile their own working copy of a field with the master copy in main memory. If a field is declared final then its value does not change and there is no need for threads to reconcile their own working copies of the variable with the master copy in main memory.  
9a  b  c  d  e  f  A variable that is local to a method can not be accessed from outside of the class, so the access modifiers are not useful and not legal. A variable that is local to a method can not be part of the persistent state of an object, so the transient modifier is not useful and not legal. Local variables can not be shared between threads, so the volatile modifier is not useful and not legal. A local variable can be declared final to prevent its value from being assigned more than once. If the value of the variable needs to be accessed from a local class or an anonymous class, then the local variable or method parameter must be declared final.  
10c  g  The abstract modifier can be applied to a class and a method but not a field. A field is sometimes shared between threads. The volatile modifier is used to force threads to reconcile their own working copy of a field with the master copy in main memory. If a field is declared final then its value does not change and there is no need for threads to reconcile their own working copies of the variable with the master copy in main memory.  
11 The synchronized modifier is a method modifier and can not be applied to a field.  
12d  f  h  The first letter of an identifier can be any Unicode JLS 3.1 character that is a Java letter. The first letter can not be a number. For historical reasons, the dollar sign $ and underscore _ are considered Java letters along with many currency symbols in use in the world today.  

Copyright © 2002-2003, Dan Chisholm
All rights reserved.