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. What is the purpose of making a method 'synchronized'?
It indicates that a method can only be accessed by one thread at a time.
At compilation
8 bytes - 2^63 -1.
abstract
2. 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.
access modifiers - abstract modifier - other non-access modifiers - return type - method name - parenthesis - semi-colon. e.g.: public abstract String getName();
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.
3. Where can the brackets for an array declaration go?
No other class can extend it.
final (cannot use static - final - abstract - volatile or transient)
On either side of the variable name - e.g.: String [] var; String var [];
Yes. Beware though that they point to the same object on the heap - whereas primitives maintain separate values.
4. What kind of error (run-time or compile) do you get when trying to extend a final class?
Only one public class
Either the same or a SUBTYPE of the original method's return type.
Compilation
8 bytes - 2^63 -1.
5. What is the purpose of making a class 'abstract'?
inside a Class
The abstract class can never be instantiated. It must be extended to be used.
Either the same or a SUBTYPE of the original method's return type.
IEEE 754
6. Which of the three non-access modifiers (strictfp - final - abstract) can and can't be used together in a class declaration?
7. What is the effect of making a method argument final?
a method?
The argument cannot be reassigned to a different object/value within the method.
Only one public 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.
8. When overriding a method - the return type must be what?
9. What is the basic construction for calling an Enum value?
No - the enum only calls it within itself.
'native'
EnumName.VALUE;
variables
10. An instance variable cannot be...
Either the same or a SUBTYPE of the original method's return type.
IEEE 754
Yes - it is. Identifiers can begin with currency symbols.
abstract
11. Can a private method be overriden by a subclass?
12. What is the code format for an abstract method?
access modifiers - abstract modifier - other non-access modifiers - return type - method name - parenthesis - semi-colon. e.g.: public abstract String getName();
enum EnumName { VALUE1 - VALUE 2 - VALUEX }; Take special note of the ending semicolon - which is optional.
At compilation
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.
13. Can a file have no public classes?
No other class can extend it.
Object a - b - c; or Object a -b -c = new Object();
Yes - technically speaking.
Compilation
14. How many classes can a class extend?
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.
Only one
Volatile forces the JVM to reconcile the private field with the one in master memory. Won't generally be covered on test.
'native'
15. What kinds of exceptions can an overriding method throw that the original does not have?
Either the same or a SUBTYPE of the original method's return type.
At the end of the list.
An unchecked exceptions.
No - they can be their own file.
16. When accessing an object you really don't have access to (it's 'private' or 'default' in another package - etc) - when will you get an error: at compilation or at run-time?
17. Local ________ can be marked final
No limit. Notice: Only overriden instance methods are dynamically invoked based on the real object's type. This does not apply to static methods nor instance variables. ...
No - the type cannot change - only the object to which it points can change.
variables
8 bytes - 2^63 -1.
18. What is the purpose of making a method 'native'?
4 bytes - 2^31 - 1.
The original can be overriden if is public or protected and not final.
It allows platform-dependent code - like C. It can only be used to modify a method (not a class or field).
equals(Object) - clone() - notify() - wait(empty/long/long - int) - finalize() - getClass() - hashCode() - toString() - & notifyAll()
19. Enums cannot be declared inside...
2 Bytes - 2^15 - 1.
a method?
default and public. Protected and private modifiers are not permissible and will give a compile time error.
Java SE 5.0
20. How many bits does a primitive 'float' hold?
variables
No limit.
32 bits.
a method?
21. For any method to be abstract - what must also be true about the class?
At compilation
override
strictfp and final are legal - strictfp and abstract are legal - but you can't put final and abstract together.
The class must be abstract in order to have any abstract methods (or it could be an interface rather than a class).
22. How many interfaces can a class implement?
23. What are the only two access modifiers valid for a Class?
It prevents the field from being serialized as the JVM will skip it.
No limit.
At the end of the list.
default and public. Protected and private modifiers are not permissible and will give a compile time error.
24. Calling what method will return an Array of Enum values?
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.
Exactly the same as the original method.
.values()
It indicates that a method can only be accessed by one thread at a time.
25. When overriding a method - the argument list (i.e. signature) must be what?
final - abstract - static - synchronized - native - & strictfp
No - they can be their own file.
It allows platform-dependent code - like C. It can only be used to modify a method (not a class or field).
Exactly the same as the original method.
26. The following field is defined in an interface. What do we know about it's access and non-access modifiers? int aNumber = 59;
27. 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.
final (cannot use static - final - abstract - volatile or transient)
Public and Abstract
IEEE 754
28. What modifiers can you use with method parameters?
final (cannot use static - final - abstract - volatile or transient)
final - abstract - static - synchronized - native - & strictfp
Only classes in the same package. The public methods are restricted by the default class level access.
strictfp - final - and abstract
29. When would you get an error for a class declaration as follows and why? - protected class Me { }
30. What is the syntax for declaring multiple variables on one line?
The very first line - excepting any comments.
abstract
4 bytes - 2^31 - 1.
Object a - b - c; or Object a -b -c = new Object();
31. What is the purpose of making a field 'transient'?
The original can be overriden if is public or protected and not final.
Java SE 5.0
It prevents the field from being serialized as the JVM will skip it.
extend another interface
32. What occurs when a class is marked as 'final'?
abstract
Only one
No limit. Notice: Only overriden instance methods are dynamically invoked based on the real object's type. This does not apply to static methods nor instance variables. ...
No other class can extend it.
33. What are the rules for checked exceptions in overriding a method?
5.0
Only one public class
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.
Public and Abstract
34. Can you make an overriding method more access restrictive (public to private) or less restrictive (private to public)?
2 Bytes - 2^15 - 1.
It cannot be more restrictive. It CAN be less restrictive than the supertype method.
The class must be abstract in order to have any abstract methods (or it could be an interface rather than a class).
abstract
35. You cannot _____ a static method
override
It prevents the field from being serialized as the JVM will skip it.
No limit.
64 bits.
36. Do Enums have to be within an existing class?
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.
No - they can be their own file.
Only one public class
enum EnumName { VALUE1 - VALUE 2 - VALUEX }; Take special note of the ending semicolon - which is optional.
37. What is the length in bytes of type 'int' - and what is it's maximum size?
Public and Abstract
4 bytes - 2^31 - 1.
Technically no. A 'fresh' method with the same name - return type and signature could be made in the subclass - but there is complete separation between the one in the superclass and subclass.
Compilation. Classes can't be modified as protected (or private).
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.
HiThereSally.java because the file name must exactly match the public class name (excepting the .java extension).
2 Bytes - 2^15 - 1.
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.
39. An interface method cannot be...
byte - short - int - long - float - double - boolean - and char
modified with strictfp
64 bits.
Volatile forces the JVM to reconcile the private field with the one in master memory. Won't generally be covered on test.
40. If a class's public class declaration is something like - 'public class HiThereSally {' - what must the source code file be named? Why?
Object type - ellipsis - object reference variable. e.g. doStuff(String ... necklace) { }
default and public. Protected and private modifiers are not permissible and will give a compile time error.
HiThereSally.java because the file name must exactly match the public class name (excepting the .java extension).
Yes. Beware though that they point to the same object on the heap - whereas primitives maintain separate values.
41. What is the length in bytes of type 'short' - and what is it's maximum size?
IEEE 754
public - final - and static. However - these modifiers are implicit and do not have to be typed. Interfaces only have Constants.
2 Bytes - 2^15 - 1.
Java SE 5.0
42. Can an abstract class have a final method?
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.
Yes - as long as the final method has code in curly braces.
8 bytes - 2^63 -1.
EnumName.VALUE;
43. 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.
2 Bytes - 2^15 - 1.
64 bits.
.values()
44. If a class is abstract - do the methods which ares supposed to be abstract too need to be marked 'abstract'?
45. What are the seven non-access modifiers for methods?
final - abstract - static - synchronized - native - & strictfp
No limit.
Only one
Compilation.
46. Does an override have to throw all the exceptions of the original method?
Subtype.
Object a - b - c; or Object a -b -c = new Object();
Technically no. A 'fresh' method with the same name - return type and signature could be made in the subclass - but there is complete separation between the one in the superclass and subclass.
No. It can throw less or no exceptions.
47. How many arguments can an Enum constructor have?
modified with strictfp
No limit.
No limit. Notice: Only overriden instance methods are dynamically invoked based on the real object's type. This does not apply to static methods nor instance variables. ...
Public and Abstract
48. When are class instance variables instantiated?
When the class is instantiated (not at compile or run time).
Volatile forces the JVM to reconcile the private field with the one in master memory. Won't generally be covered on test.
strictfp and final are legal - strictfp and abstract are legal - but you can't put final and abstract together.
Technically no. A 'fresh' method with the same name - return type and signature could be made in the subclass - but there is complete separation between the one in the superclass and subclass.
49. How many non public classes can be in any one file?
4 bytes - 2^31 - 1.
final (cannot use static - final - abstract - volatile or transient)
No limit.
Compilation.
50. An ________cannot be static?
Just one.
interface method
No limit. Notice: Only overriden instance methods are dynamically invoked based on the real object's type. This does not apply to static methods nor instance variables. ...
instance