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