Basic Flashcards Preview

OCA Java SE 7 Certification (1ZO-803) > Basic > Flashcards

Flashcards in Basic Deck (13)
Loading flashcards...
1
Q

Order the following by when they are initialized:

  1. All non static constants, variables and blocks.
  2. Constructor.
  3. All static constants, variables and blocks.
A

2, 3, 1

- Among themselves the order is the order in which they appear in the code.

2
Q

Which method declarations will enable a class to be run as a standalone program:

  1. static void main(String args[ ])
  2. public void static main(String args[ ])
  3. public static main(String[ ] argv)
  4. final public static void main(String [ ] array)
  5. public static void main(String args[ ])
A

4, 5

  • the accessibility of the main method must be public.
  • return type and method name are never separated
3
Q

True/false:

  1. An object can be made eligible for garbage collection by making sure there are no references pointing to that object.
  2. You cannot directly invoke the garbage collector.
A

True

- You can however suggest the JVM to perform garbage collection by calling System.gc();

4
Q

Which of these statements concerning the use of modifiers are true:

  1. By default the member is only accessible to classes in the same package and subclasses of the class.
  2. You cannot specify visibility of local variables.
  3. Local variable always have default accessibility.
  4. Local variables can be declared as private.
  5. Local variables can only be declared as public.
A

2

5
Q

True/false:

You cannot apply any modifier except final

A

True.

- i.e. you cannot make them transient, volatile, static, public, and private.

6
Q

True/false:

A method that has a body can be abstract.

A

False.

- an abstract method cannot have a body.

7
Q

The following is a valid member variable declaration: private static final transient int i = 20;

A

True.

- You can apply all the modifiers to member variables except abstract, native and synchronized.

8
Q

True/false: The following import statement is valid:

static import java.lang.System.*;

A

False

- The order of static and import is invalid. It should have been “import static”.

9
Q

True/false: It is not required to import java.io.* or import java.io.IOException because java.io package is imported automatically.

A

False.

- Only java.lang package is imported automatically.

10
Q

What does the zeroth element of the string array passed to the standard main method contain:

  1. The name of the class.
  2. The string “java”.
  3. The number of arguments.
  4. The first argument of the argument list, if present.
  5. None of the above.
A

4.

- If no argument is passed the args parameter is NOT null but a valid non-null String array of length zero.

11
Q

An instance member …

  1. can be a variable, a constant or a method.
  2. is a variable or a constant.
  3. belongs to the class.
  4. belongs to an instance of the class.
  5. is same as a local variable.
A
1, 4
- An instance member belongs to a single instance, not the class as a whole. An instance member is a member variable or a member method that belongs to a specific object instance. All non-static members are instance members.
12
Q

True/false:
Syntax for importing static fields is: import static ..*;
or import static ..;

A

True.

13
Q

How can you declare a method someMethod() such that an instance of the class is not needed to access it and all the members of the same package have access to it:

  1. public static void someMethod()
  2. static void someMethod()
  3. protected static void someMethod()
  4. void someMethod()
  5. protected void someMethod()
  6. public abstract static void someMethod()
A

1, 2, 3

- must be static