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