Java Flashcards
What keyword would be used to refer to the current class instance variable, in order to resolve ambiguity between instance variables & parameters?
this
Why might the this keyword be used to invoke the current class constructor?
To reuse the constructor i.e. for constructor chaining
The new operator is followed by a call to a ____, which initializes a new object.
Class constructor
The super keyword can be used to refer to a parent class instance variable if what is true?
The parent class and child class have the same fields
When should the super keyword be used to invoke a parent class method?
If the child class contains the same method as the parent class i.e if the method is being overwritten
What four things can the static keyword be applied with?
Variables, methods, blocks, nested classes
Where can the final keyword be initialized?
In the constructor
What string handling method returns a character at a specified index?
char charAt(int index)
What string handling method compares the current string to another object?
int compareTo(Object o)
What string handling method concatenates the specified string to the end of the current string?
String concat(String str)
What string handling method compares the current string to the specified object?
boolean equals(Object anObject)
What string handling method compares the current string to another string while ignoring case considerations?
boolean equalsIgnoreCase(String anotherString)
What in Java is a group of similar types of classes & interfaces?
Package
What are the three advantages of packages?
Categorizing classes & interfaces; providing access protection; removing naming collision
What are the three ways to access a package from other packages?
import package.*; import package.classname; using the fully qualified name.
If the import package.* syntax is used, then which of the following three will not be accessible? Classes, interfaces, subpackages
Subpackages
If the import package.classname syntax is used, what is the only part of the package that will be accessible?
Declared class
When is the fully qualified name of a package generally used?
Two packages have the same class name / To prevent class name collision
What is the ordering sequence of a Java program?
Package > import > class
What is a reference type in Java that is similar to class and is a collection of abstract methods?
Interface
Besides abstract methods, what 3 or 4 things may an interface also contain?
Constants, default or static methods, nested types
All the methods of an interface implemented by a class need to be defined in the class, unless what is true?
The class is abstract