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