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