SUBJECTS
|
BROWSE
|
CAREER CENTER
|
POPULAR
|
JOIN
|
LOGIN
Business Skills
|
Soft Skills
|
Basic Literacy
|
Certifications
About
|
Help
|
Privacy
|
Terms
|
Email
Search
Test your basic knowledge |
Oracle Sun Certified Java Programmer
Start Test
Study First
Subjects
:
certifications
,
it-skills
Instructions:
Answer 50 questions in 15 minutes.
If you are not ready to take this test, you can
study here
.
Match each statement with the correct term.
Don't refresh. All questions and answers are randomly picked and ordered every time you load a test.
This is a study tool. The 3 wrong answers for each question are randomly chosen from answers to other questions. So, you might find at times the answers obvious, but you will see it re-enforces your understanding as you take the test each time.
1. The following field is defined in an interface. What do we know about it's access and non-access modifiers? int aNumber = 59;
2. For any method to be abstract - what must also be true about the class?
The class must be abstract in order to have any abstract methods (or it could be an interface rather than a class).
Interface methods are always public. A lack of modifier does not make this 'default' in the typical sense of a package-only default access modifier.
strictfp and final are legal - strictfp and abstract are legal - but you can't put final and abstract together.
Object a - b - c; or Object a -b -c = new Object();
3. What is the effect of making a method argument final?
It allows platform-dependent code - like C. It can only be used to modify a method (not a class or field).
interface method
An unchecked exceptions.
The argument cannot be reassigned to a different object/value within the method.
4. Where can the brackets for an array declaration go?
It allows platform-dependent code - like C. It can only be used to modify a method (not a class or field).
Compilation
Compilation. Classes can't be modified as protected (or private).
On either side of the variable name - e.g.: String [] var; String var [];
5. What is the purpose of an Enum?
Only classes in the same package. The public methods are restricted by the default class level access.
The argument cannot be reassigned to a different object/value within the method.
The override cannot throw BROADER exceptions nor NEW exceptions. If an exception is a subclass of the original exception - it can be thrown and still be an override. The override can also throw less exceptions.
To limit values to a predetermined set.
6. If a class is abstract - do the methods which ares supposed to be abstract too need to be marked 'abstract'?
7. What are the rules for checked exceptions in overriding a method?
The override cannot throw BROADER exceptions nor NEW exceptions. If an exception is a subclass of the original exception - it can be thrown and still be an override. The override can also throw less exceptions.
No limit.
At compilation.
Subtype.
8. An original method that will be overriden by a class not in the same package as the original could have what access levels and still be considered an 'override'?
variables
No limit.
The argument cannot be reassigned to a different object/value within the method.
The original can be overriden if is public or protected and not final.
9. What occurs when a class is marked as 'final'?
Subtype.
No other class can extend it.
abstract
synchronized - or - native
10. How many non public classes can be in any one file?
No - Identifiers cannot begin with numbers - further more identifiers may not contain hyphens.
Just one.
No limit.
Compile and Run time. It will normally happen at compilation - but in case the 'private' method class was changed to private/default/protected after the calling class was compiled - it will be a Run Time 'IllegalAccessError' exception.
11. When overriding a method - the argument list (i.e. signature) must be what?
Exactly the same as the original method.
Compilation. Classes can't be modified as protected (or private).
You must implement every abstract method in the abstract class - as well as every method defined in the interface. Except... however - if a supertype has already made implementation of the abstract methods.
IEEE 754
12. What is the purpose of making a method 'native'?
variables
It cannot be more restrictive. It CAN be less restrictive than the supertype method.
access modifiers - abstract modifier - other non-access modifiers - return type - method name - parenthesis - semi-colon. e.g.: public abstract String getName();
It allows platform-dependent code - like C. It can only be used to modify a method (not a class or field).
13. What is the proper syntax for declaring a var-arg in a method signature?
Object type - ellipsis - object reference variable. e.g. doStuff(String ... necklace) { }
64 bits.
inside a Class
You must implement every abstract method in the abstract class - as well as every method defined in the interface. Except... however - if a supertype has already made implementation of the abstract methods.
14. An instance variable cannot be...
abstract
modified with strictfp
Public and Abstract
No limit.
15. Enums can be declared outside a Class - but in...
Only one
'native'
Compile and Run time. It will normally happen at compilation - but in case the 'private' method class was changed to private/default/protected after the calling class was compiled - it will be a Run Time 'IllegalAccessError' exception.
the same file
16. How many var-arg's can you have in a method signature?
Yes - technically speaking.
Just one.
At compilation.
Yes - as long as the final method has code in curly braces.
17. Var-args have been possible since what Java version?
Yes. Abstract methods must be marked as abstract - even if the class is abstract. However this isn't true with Interfaces: all methods in an interface are by default abstract as no non-abstract methods can exist in an Interface.
8 bytes - 2^63 -1.
At the end of the list.
Java SE 5.0
18. At what point will you get an error if an interface method is 'protected' or 'private'?
Compilation.
No. It can throw less or no exceptions.
The original can be overriden if is public or protected and not final.
The very first line - excepting any comments.
19. What Java version began allowing an Enum type?
the same file
Yes. Abstract methods must be marked as abstract - even if the class is abstract. However this isn't true with Interfaces: all methods in an interface are by default abstract as no non-abstract methods can exist in an Interface.
Compile and Run time. It will normally happen at compilation - but in case the 'private' method class was changed to private/default/protected after the calling class was compiled - it will be a Run Time 'IllegalAccessError' exception.
5.0
20. What is the purpose of making a method 'synchronized'?
final (cannot use static - final - abstract - volatile or transient)
'native'
It indicates that a method can only be accessed by one thread at a time.
Subtype.
21. What is the purpose of making a class 'abstract'?
Yes. Beware though that they point to the same object on the heap - whereas primitives maintain separate values.
The original can be overriden if is public or protected and not final.
The abstract class can never be instantiated. It must be extended to be used.
variables
22. When overriding a method - the return type must be what?
23. What are the built-in methods for class Object?
Yes - it is. Identifiers can begin with currency symbols.
No. It can throw less or no exceptions.
final (cannot use static - final - abstract - volatile or transient)
equals(Object) - clone() - notify() - wait(empty/long/long - int) - finalize() - getClass() - hashCode() - toString() - & notifyAll()
24. How many classes can a class extend?
Only one
byte - short - int - long - float - double - boolean - and char
interface method
default and public. Protected and private modifiers are not permissible and will give a compile time error.
25. An interface method cannot be...
a method?
modified with strictfp
override
Yes - technically speaking.
26. How many arguments can an Enum constructor have?
Yes - as long as the final method has code in curly braces.
No limit.
access modifiers - abstract modifier - other non-access modifiers - return type - method name - parenthesis - semi-colon. e.g.: public abstract String getName();
Compile and Run time. It will normally happen at compilation - but in case the 'private' method class was changed to private/default/protected after the calling class was compiled - it will be a Run Time 'IllegalAccessError' exception.
27. Local ________ can be marked final
variables
Only one public class
Yes. Beware though that they point to the same object on the heap - whereas primitives maintain separate values.
The field 'aNumber' is public - static and final. The value cannot be changed -- it is a constant.
28. Once a reference variable is defined - can it's object type be changed?
Only classes in the same package. The public methods are restricted by the default class level access.
No - the type cannot change - only the object to which it points can change.
inside a Class
Compile and Run time. It will normally happen at compilation - but in case the 'private' method class was changed to private/default/protected after the calling class was compiled - it will be a Run Time 'IllegalAccessError' exception.
29. Calling what method will return an Array of Enum values?
Only classes in the same package. The public methods are restricted by the default class level access.
It cannot be more restrictive. It CAN be less restrictive than the supertype method.
.values()
'native'
30. When would you get an error for a class declaration as follows and why? - protected class Me { }
31. An interface method cannot be modified as...
32. Which of the three non-access modifiers (strictfp - final - abstract) can and can't be used together in a class declaration?
33. How many bits does a primitive 'float' hold?
32 bits.
instance
Subtype.
'native'
34. Is this identifier name valid? Why or why not? int $_myVar;
Either the same or a SUBTYPE of the original method's return type.
Object type - ellipsis - object reference variable. e.g. doStuff(String ... necklace) { }
Yes - it is. Identifiers can begin with currency symbols.
At compilation
35. What three non-access modifiers can be used with a class declaration?
5.0
strictfp and final are legal - strictfp and abstract are legal - but you can't put final and abstract together.
strictfp - final - and abstract
variables
36. What is the syntax for declaring multiple variables on one line?
Only one
The very first line - excepting any comments.
Object a - b - c; or Object a -b -c = new Object();
Volatile forces the JVM to reconcile the private field with the one in master memory. Won't generally be covered on test.
37. Do Enums have to be within an existing class?
The very first line - excepting any comments.
Object a - b - c; or Object a -b -c = new Object();
No - they can be their own file.
inside a Class
38. How many bits does a primitive 'double' hold?
On either side of the variable name - e.g.: String [] var; String var [];
Interface methods are always public. A lack of modifier does not make this 'default' in the typical sense of a package-only default access modifier.
64 bits.
inside a Class
39. A class is access modified as default. It's methods are access modified as 'public'. What other class files can access the methods in this class?
Volatile forces the JVM to reconcile the private field with the one in master memory. Won't generally be covered on test.
At compilation
32 bits.
Only classes in the same package. The public methods are restricted by the default class level access.
40. An ________cannot be static?
a method?
interface method
override
No limit.
41. Enums cannot be declared inside...
Either the same or a SUBTYPE of the original method's return type.
a method?
equals(Object) - clone() - notify() - wait(empty/long/long - int) - finalize() - getClass() - hashCode() - toString() - & notifyAll()
At compilation.
42. What kinds of exceptions can an overriding method throw that the original does not have?
An unchecked exceptions.
64 bits.
Public and Abstract
default and public. Protected and private modifiers are not permissible and will give a compile time error.
43. What is the length in bytes of type 'int' - and what is it's maximum size?
'native'
4 bytes - 2^31 - 1.
Exactly the same as the original method.
When the class is instantiated (not at compile or run time).
44. Enums can be declared...
Exactly the same as the original method.
Only one
No - they can be their own file.
inside a Class
45. What is a 'constant specific class body' and where can you use it?
In an Enum declaration - it allows you to override an Enum default methods and values. You use it in the Enum value declaration list - just after the value in curly braces.
No limit.
Yes - it is. Identifiers can begin with currency symbols.
synchronized - or - native
46. What are the only two access modifiers valid for a Class?
inside a Class
default and public. Protected and private modifiers are not permissible and will give a compile time error.
strictfp and final are legal - strictfp and abstract are legal - but you can't put final and abstract together.
Public and Abstract
47. Is this identifier name valid? Why or why not? int 34myVar-Yes;
Subtype.
To limit values to a predetermined set.
No - Identifiers cannot begin with numbers - further more identifiers may not contain hyphens.
HiThereSally.java because the file name must exactly match the public class name (excepting the .java extension).
48. What kind of error (run-time or compile) do you get when trying to extend a final class?
An unchecked exceptions.
Compilation
The class must be abstract in order to have any abstract methods (or it could be an interface rather than a class).
public - final - and static. However - these modifiers are implicit and do not have to be typed. Interfaces only have Constants.
49. What access level does the following interface method have? void getSomething(); public.
50. When you try to use a method that you don't have access to (due to 'private' etc) - when do you get an error?
At compilation.
No - Identifiers cannot begin with numbers - further more identifiers may not contain hyphens.
synchronized - or - native
modified with strictfp