Writing Classes in AP Computer Science A
Which of the following variables can be accessed by any class in the same package and/or an external subclass of the class its in?
private int num = 5;
There is no such modifier that allows this kind of access for variables.
int num = 5;
protected int num = 5;
Which kind of testing checks specific parts of software to ensure they behave as intended in isolation from other components?
Acceptance Testing
Unit Testing
Integration Testing
System Testing
Which of the following standard algorithms can be used to search for an element in an unsorted array and will always require examining each element at least once if the element is not present?
Insertion sort
Linear search
Binary search
Merge sort
In Java programming language constants are defined using which modifier combination?
private final
public transient
volatile const
final static
Which data structure should be used to ensure the fastest retrieval of elements inserted in sorted order without additional sorting steps after each insertion?
Stack
PriorityQueue
Vector
ArrayList
What is an example of an instance variable in Java?
One that is declared within a class but not within a method block
Local one that is declared within a method block
Global one that is declared outside of any class
Parameter one that is passed into a method
If a public instance method m1() calls another private instance method m2() within the same class, which statement accurately describes this scenario?
Private method m2() cannot be called by any other methods because it is private.
Method m1() needs an object reference to call method m2(), even though it's in the same class.
Method m1() must also be private if it wants to call any private methods like m2().
Method m1() has access to call method m2() because both are members of the same class.

How are we doing?
Give us your feedback and let us know how we can improve
Given four fields defined at the top of a class, which one will remain accessible after an object of the class has been garbage collected?
The public field since its accessibility is supposed to be broadest of all
None of the fields remain accessible as the entire object is no longer in memory
The static field because it is pertained to the class and not to individual instances
The protected field as it may still be in use by other objects derived from this class
In object-oriented design, when should a programmer prefer composition over inheritance?
When implementing interfaces that require multiple inheritances.
When methods from the superclass need to be overridden extensively.
When wanting to use some aspects of another class without establishing a subtype relationship.
When there is a clear is-a relationship between the objects.
In Java, which keyword would you use to declare a constant whose value should not change after initialization and must be accessible only within its own class?
private final
public final
protected final
public static