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