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. What are the seven non-access modifiers for methods?
final - abstract - static - synchronized - native - & strictfp
An unchecked exceptions.
inside a Class
It allows platform-dependent code - like C. It can only be used to modify a method (not a class or field).
3. An interface method cannot be modified as...
4. What is the length in bytes of type 'short' - and what is it's maximum size?
2 Bytes - 2^15 - 1.
Compilation. Classes can't be modified as protected (or private).
modified with strictfp
Either the same or a SUBTYPE of the original method's return type.
5. Enums cannot be declared inside...
Yes - as long as the final method has code in curly braces.
a method?
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.
interface method
6. An ________ variable cannot be marked strictfp
'native'
instance
To limit values to a predetermined set.
The class must be abstract in order to have any abstract methods (or it could be an interface rather than a class).
7. What Java version began allowing an Enum type?
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.
Just one.
Subtype.
5.0
8. What is a 'constant specific class body' and where can you use it?
final - abstract - static - synchronized - native - & strictfp
Public and Abstract
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.
It cannot be more restrictive. It CAN be less restrictive than the supertype method.
9. What are the only two access modifiers valid for a Class?
default and public. Protected and private modifiers are not permissible and will give a compile time error.
At compilation
Only one
public - final - and static. However - these modifiers are implicit and do not have to be typed. Interfaces only have Constants.
10. How many bits does a primitive 'double' hold?
default and public. Protected and private modifiers are not permissible and will give a compile time error.
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.
The class must be abstract in order to have any abstract methods (or it could be an interface rather than a class).
64 bits.
11. 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'?
At the end of the list.
Java SE 5.0
8 bytes - 2^63 -1.
The original can be overriden if is public or protected and not final.
12. Where can the brackets for an array declaration go?
Yes - as long as the final method has code in curly braces.
No limit.
On either side of the variable name - e.g.: String [] var; String var [];
final - abstract - static - synchronized - native - & strictfp
13. Can multiple non-primitive variables be defined in one line?
IEEE 754
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.
Yes. Beware though that they point to the same object on the heap - whereas primitives maintain separate values.
When the class is instantiated (not at compile or run time).
14. Can an abstract class have a final method?
No - Identifiers cannot begin with numbers - further more identifiers may not contain hyphens.
Yes - as long as the final method has code in curly braces.
inside a Class
At compilation
15. Putting abstract and final in the class declaration will give you a run-time or compile time error?
Either the same or a SUBTYPE of the original method's return type.
Yes - as long as the final method has code in curly braces.
At compilation
Compilation.
16. At what point will you get an error if an interface method is 'protected' or 'private'?
Compilation.
instance
a method?
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.
17. Do Enums have to be within an existing class?
No - they can be their own file.
No limit.
variables
In the same <i>package</i> it can be public - protected - or default and cannot be final or private.
18. A reference variable can be reassigned to another object that is of the same type. It can also be reassigned to a supertype or subtype of the original type?
Subtype.
Just one.
variables
EnumName.VALUE;
19. Can a private method be overriden by a subclass?
20. All fields in an interface must have what three access & non-access modifiers?
public - final - and static. However - these modifiers are implicit and do not have to be typed. Interfaces only have Constants.
Either the same or a SUBTYPE of the original method's return type.
default and public. Protected and private modifiers are not permissible and will give a compile time error.
No other class can extend it.
21. Can a subclass see and use inherited 'private' methods and fields?
22. What are the built-in methods for class Object?
byte - short - int - long - float - double - boolean - and char
a method?
equals(Object) - clone() - notify() - wait(empty/long/long - int) - finalize() - getClass() - hashCode() - toString() - & notifyAll()
At compilation
23. What are the rules for checked exceptions in overriding a method?
extend another interface
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.
Object type - ellipsis - object reference variable. e.g. doStuff(String ... necklace) { }
The argument cannot be reassigned to a different object/value within the method.
24. When would you get an error for a class declaration as follows and why? - protected class Me { }
25. Enums can be declared outside a Class - but in...
the same file
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.
override
An unchecked exceptions.
26. Can you make an overriding method more access restrictive (public to private) or less restrictive (private to public)?
Yes - as long as the final method has code in curly braces.
It allows platform-dependent code - like C. It can only be used to modify a method (not a class or field).
It cannot be more restrictive. It CAN be less restrictive than the supertype method.
Only one
27. An original method that will be overriden by a class in the same package as the original could have what access levels and still be considered an 'override'?
64 bits.
Compilation.
In the same <i>package</i> it can be public - protected - or default and cannot be final or private.
4 bytes - 2^31 - 1.
28. How many bits does a primitive 'float' hold?
equals(Object) - clone() - notify() - wait(empty/long/long - int) - finalize() - getClass() - hashCode() - toString() - & notifyAll()
32 bits.
The original can be overriden if is public or protected and not final.
In the same <i>package</i> it can be public - protected - or default and cannot be final or private.
29. What is the proper syntax for declaring a var-arg in a method signature?
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 type - ellipsis - object reference variable. e.g. doStuff(String ... necklace) { }
equals(Object) - clone() - notify() - wait(empty/long/long - int) - finalize() - getClass() - hashCode() - toString() - & notifyAll()
30. What is the purpose of making a method 'synchronized'?
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 argument cannot be reassigned to a different object/value within the method.
Volatile forces the JVM to reconcile the private field with the one in master memory. Won't generally be covered on test.
It indicates that a method can only be accessed by one thread at a time.
31. Once a reference variable is defined - can it's object type be changed?
Object a - b - c; or Object a -b -c = new Object();
final (cannot use static - final - abstract - volatile or transient)
To limit values to a predetermined set.
No - the type cannot change - only the object to which it points can change.
32. What is the purpose of making a method 'native'?
No limit.
It allows platform-dependent code - like C. It can only be used to modify a method (not a class or field).
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.
extend another interface
33. Where in the source code must a 'package' statement be?
4 bytes - 2^31 - 1.
It prevents the field from being serialized as the JVM will skip it.
The very first line - excepting any comments.
EnumName.VALUE;
34. What is the purpose of making a class 'abstract'?
Volatile forces the JVM to reconcile the private field with the one in master memory. Won't generally be covered on test.
Exactly the same as the original method.
No limit.
The abstract class can never be instantiated. It must be extended to be used.
35. When are class instance variables instantiated?
When the class is instantiated (not at compile or run time).
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.
enum EnumName { VALUE1 - VALUE 2 - VALUEX }; Take special note of the ending semicolon - which is optional.
5.0
36. If an Enum has a constructor - can you call that constructor?
No - the enum only calls it within itself.
Either the same or a SUBTYPE of the original method's return type.
Subtype.
64 bits.
37. What is the code format for an abstract method?
equals(Object) - clone() - notify() - wait(empty/long/long - int) - finalize() - getClass() - hashCode() - toString() - & notifyAll()
Java SE 5.0
Exactly the same as the original method.
access modifiers - abstract modifier - other non-access modifiers - return type - method name - parenthesis - semi-colon. e.g.: public abstract String getName();
38. Is this identifier name valid? Why or why not? int 34myVar-Yes;
No - Identifiers cannot begin with numbers - further more identifiers may not contain hyphens.
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.
a method?
Only one
39. Local ________ can be marked final
Subtype.
To limit values to a predetermined set.
variables
No - they can be their own file.
40. What is the purpose of making a field 'volatile'?
41. What is the syntax for declaring multiple variables on one line?
Object a - b - c; or Object a -b -c = new Object();
Either the same or a SUBTYPE of the original method's return type.
enum EnumName { VALUE1 - VALUE 2 - VALUEX }; Take special note of the ending semicolon - which is optional.
No limit.
42. What kinds of exceptions can an overriding method throw that the original does not have?
Object a - b - c; or Object a -b -c = new Object();
An unchecked exceptions.
Subtype.
In the same <i>package</i> it can be public - protected - or default and cannot be final or private.
43. An interface method cannot be...
The very first line - excepting any comments.
override
modified with strictfp
The argument cannot be reassigned to a different object/value within the method.
44. What kind of error (run-time or compile) do you get when trying to extend a final class?
An unchecked exceptions.
Compilation
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.
Yes - technically speaking.
45. When overriding a method - the argument list (i.e. signature) must be what?
Exactly the same as the original method.
EnumName.VALUE;
modified with strictfp
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.
46. An instance variable cannot be marked...
When the class is instantiated (not at compile or run time).
synchronized - or - native
abstract
No limit.
47. What modifiers can you use with method parameters?
Volatile forces the JVM to reconcile the private field with the one in master memory. Won't generally be covered on test.
extend another interface
final (cannot use static - final - abstract - volatile or transient)
Yes - as long as the final method has code in curly braces.
48. You cannot _____ a static method
In the same <i>package</i> it can be public - protected - or default and cannot be final or private.
Only classes in the same package. The public methods are restricted by the default class level access.
override
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.
49. What must you do when extending an abstract class or implementing any interface?
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.
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.
inside a Class
No limit.
50. What is the purpose of making a field 'transient'?
In the same <i>package</i> it can be public - protected - or default and cannot be final or private.
It prevents the field from being serialized as the JVM will skip it.
.values()
5.0