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