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