Documente Academic
Documente Profesional
Documente Cultură
Creating a Class
1. A class header contains an optional access specifier, the keyword class, and an
identifier.
2. When you instantiate objects, each has its own copy of each static data field in the
class.
3. Most fields in a class are private, and most methods are public.
TWO TRUTHS & A LIE
Initializing an Array
1. When you declare int[] idNums = new int[35];, each element of the array has a value
of 0.
2. When you declare double[] salaries = new double[10];, each element of the array
has a value of 0.0.
3. When you declare int[] scores = {100, 90, 80};, the first three elements of the array
are assigned the values listed, but all the remaining elements are assigned 0
TWO TRUTHS & A LIE
Declaring Arrays
1. The statement int[] idNums = new int[35]; reserves enough memory for exactly 34
integers.
2. The first element in any array has a subscript of 0, no matter what data type is
stored.
3. In Java, you can use a variable as well as a constant to declare an array’s size.
Automatically Imported,
Prewritten Constants and
Methods
Learning About the this Reference
1. Usually, you want each instantiation of a class to have its own non-static data fields,
but each object does not need its own copy of most methods.
2. When you use a non-static method, the compiler accesses the correct object’s field
because you implicitly pass an object reference to the method.
3. The this reference is supplied automatically in classes; you cannot use it explicitly.
TWO TRUTHS & A LIE
Initializing an Array
1. When you declare int[] idNums = new int[35];, each element of the array has a value
of 0.
2. When you declare double[] salaries = new double[10];, each element of the array has
a value of 0.0.
3. When you declare int[] scores = {100, 90, 80};, the first three elements of the array
are assigned the values listed, but all the remaining elements are assigned 0.
TWO TRUTHS & A LIE
1. The Arrays class contains methods for manipulating arrays, such as binarySearch(),
fill(), and sort().
2. You can use the Arrays class binarySearch() method successfully on any array as
soon as you have assigned values to the array elements.
3. The binarySearch() method works by continuously deciding whether the element
sought is above or below the halfway point in sublists of the original list.
TWO TRUTHS & A LIE
Extending Classes
1. You use the keyword inherits to achieve inheritance in Java.
2. A derived class has access to all its parents’ nonprivate methods.
3. Subclasses are more specific than the superclass they extend
TWO TRUTHS & A LIE
1. Any child class object has all the attributes of its parent, but all of those attributes
might not be directly accessible.
2. You override a parent class method by creating a child class method with the same
identifier but a different parameter list or return type.
3. When a child class method overrides a parent class method, and you use the
method name with a child class object, the child class method version executes.
TWO TRUTHS & A LIE
1. You can use the keyword this from within a derived class method to access an
overridden base class method.
2. You can use the keyword super from within a derived class method to access an
overridden base class method.
3. You can use the keyword super from within a derived class method to access a base
class method that has not been overridden.
TWO TRUTHS & A LIE