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