Podcast
Questions and Answers
Which of the following statements best describes the relationship between a class and an object?
Which of the following statements best describes the relationship between a class and an object?
- A class is an instance of an object.
- A class is a data type, while an object is a function.
- An object is an instance of a class. (correct)
- A class and an object are the same thing.
In a UML class diagram, how is the relationship between a subclass and its superclass represented?
In a UML class diagram, how is the relationship between a subclass and its superclass represented?
- An arrow pointing from the subclass to the superclass. (correct)
- An arrow pointing from the superclass to the subclass.
- A solid line connecting the two classes.
- A dashed line connecting the two classes.
Which access modifier provides the most restrictive level of access to a class member?
Which access modifier provides the most restrictive level of access to a class member?
- public
- private (correct)
- protected
- internal
What is the purpose of a void method?
What is the purpose of a void method?
Which of the following elements is NOT part of a method header?
Which of the following elements is NOT part of a method header?
When a method is called and returns a value, what is best practice?
When a method is called and returns a value, what is best practice?
Inside a method definition, what does the keyword this
refer to?
Inside a method definition, what does the keyword this
refer to?
What is the scope of a local variable?
What is the scope of a local variable?
Which of the following best describes the difference between a parameter and an argument?
Which of the following best describes the difference between a parameter and an argument?
What is the primary purpose of an accessor method (getter)?
What is the primary purpose of an accessor method (getter)?
What is the role of a mutator method (setter)?
What is the role of a mutator method (setter)?
If a method being called from within the same class, what is necessary?
If a method being called from within the same class, what is necessary?
What does the concept of 'information hiding' achieve in object-oriented programming?
What does the concept of 'information hiding' achieve in object-oriented programming?
What is the primary purpose of precondition comments?
What is the primary purpose of precondition comments?
What do postcondition comments primarily describe?
What do postcondition comments primarily describe?
In the context of object-oriented programming, what does encapsulation primarily achieve?
In the context of object-oriented programming, what does encapsulation primarily achieve?
What does a class interface typically consist of?
What does a class interface typically consist of?
What does the implementation of a class typically consist of?
What does the implementation of a class typically consist of?
A class is considered well-encapsulated under which condition?
A class is considered well-encapsulated under which condition?
What is the specific purpose of a constructor?
What is the specific purpose of a constructor?
What happens if no constructor is explicitly defined in a class?
What happens if no constructor is explicitly defined in a class?
What is method overloading?
What is method overloading?
What is the primary benefit of using private helper methods within a class?
What is the primary benefit of using private helper methods within a class?
What distinguishes a static variable from an instance variable?
What distinguishes a static variable from an instance variable?
Why should named constants be declared as static?
Why should named constants be declared as static?
How can you access a public static constant defined in a class from outside the class?
How can you access a public static constant defined in a class from outside the class?
What is a key characteristic of a static method?
What is a key characteristic of a static method?
If another object of a class has been explicitly created, what type of members can a static method directly access within the same class?
If another object of a class has been explicitly created, what type of members can a static method directly access within the same class?
What is the purpose of a wrapper class in Java?
What is the purpose of a wrapper class in Java?
What is the practice of 'decomposition' in programming?
What is the practice of 'decomposition' in programming?
What is a 'stub' in the context of software testing?
What is a 'stub' in the context of software testing?
Flashcards
What is an object?
What is an object?
An instance of a class.
What is a class?
What is a class?
A blueprint that defines an object's variables and methods.
What is a UML class diagram?
What is a UML class diagram?
A structural diagram representing a class, including inheritance, methods, and return types.
What is an instance variable?
What is an instance variable?
Signup and view all the flashcards
What is a method?
What is a method?
Signup and view all the flashcards
What are access modifiers?
What are access modifiers?
Signup and view all the flashcards
What is the null constant?
What is the null constant?
Signup and view all the flashcards
What is a void method?
What is a void method?
Signup and view all the flashcards
What information does a method header contain?
What information does a method header contain?
Signup and view all the flashcards
What is a method body?
What is a method body?
Signup and view all the flashcards
In a method definition, what does the keyword "this" refer to?
In a method definition, what does the keyword "this" refer to?
Signup and view all the flashcards
What is a local variable?
What is a local variable?
Signup and view all the flashcards
What is a parameter?
What is a parameter?
Signup and view all the flashcards
What is an argument?
What is an argument?
Signup and view all the flashcards
What is an accessor method/getter?
What is an accessor method/getter?
Signup and view all the flashcards
What is a mutator method/setter?
What is a mutator method/setter?
Signup and view all the flashcards
What is information hiding?
What is information hiding?
Signup and view all the flashcards
What is a precondition comment for?
What is a precondition comment for?
Signup and view all the flashcards
What is a postcondition comment for?
What is a postcondition comment for?
Signup and view all the flashcards
What does encapsulation mean?
What does encapsulation mean?
Signup and view all the flashcards
What does the implementation of a class consist of?
What does the implementation of a class consist of?
Signup and view all the flashcards
What is a constructor?
What is a constructor?
Signup and view all the flashcards
What are private helper methods?
What are private helper methods?
Signup and view all the flashcards
What is a static variable?
What is a static variable?
Signup and view all the flashcards
What is decomposition?
What is decomposition?
Signup and view all the flashcards
What is overloading?
What is overloading?
Signup and view all the flashcards
What is an array, and what is an array element?
What is an array, and what is an array element?
Signup and view all the flashcards
What is a searching algorithm?
What is a searching algorithm?
Signup and view all the flashcards
What is an exception?
What is an exception?
Signup and view all the flashcards
What is inheritance?
What is inheritance?
Signup and view all the flashcards
Study Notes
- An object is an instance of a class
Classes
- A class is a blueprint that defines an object's variables and methods.
- A UML class diagram is a structural diagram representing a class (or multiple), including inheritance, methods, and return types.
- Subclasses in UML diagrams are depicted with an arrow pointing from the subclass to the superclass
- Instance variables are members of a class instance.
- Methods are preset instruction sequences executed when called.
- Access modifiers, like "private" or "public," determine the level of access (scope); "private" is limited to the class, while "public" is accessible everywhere.
- A null constant is neither an object nor a type, representing an absent value or "nothing."
- A void method does not return a value.
- A method header includes access modifiers, return type, method name, and a parameter list.
- A method body contains the sequence of statements to be executed when the method is called, enclosed in { }.
- Methods can be defined to return a value, which should be stored in a variable when the method is called.
- In a method definition, "this" refers to the object performing the action specified by the method.
- A local variable is defined within a method or block with local scope and is inaccessible outside its declaration.
- A parameter is a variable passed into a method or constructor needed to perform its tasks.
- An argument is a value passed into a method, matching its parameters.
- Accessor methods or getters access private values, which hides implementation details and is an important practice in encapsulation.
- Mutator methods or setters change the values of private values indirectly.
- A method body can contain a call to another method.
- If a called method is in the same class, the receiving object does not need specification, only if the call occurs outside the class scope.
- Information hiding protects implementation details from the programmer who knows what a method does, but not how it does it.
- Comments specify what a method does, such as precondition and postcondition comments.
- Precondition comments define the conditions that must be true before a method is called.
- Postcondition comments specify the effects produced by a method call.
- Encapsulation hides unnecessary class details to simplify the understanding of objects and class usage.
- A class interface consists of public method headers and any public named constants in the class.
- The implementation of a class consists of instance variables and method definitions.
- A class is well-encapsulated when changes can be made to the implementation without altering the class interface.
- A constructor is a special method called when the "new" keyword is used.
- A constructor with no arguments is called a default constructor.
- Java defines default constructors that initialize private instance variables to default values if no constructor is defined.
- Multiple constructors can be defined with different numbers or types of parameters; this is called overloading.
- Constructors with parameters require arguments to be invoked.
- Private helper methods are created for tasks only necessary within a class to aid in performing tasks and providing organization.
- Each object of a class has its own copy of an instance variable.
- A static variable is shared by all objects of a class.
- Static variables are declared with the "static" keyword.
- Named constants should be declared as static since there's no need for copies if a variable never changes.
- To access a static constant or variable outside a class, it must be preceded by the class name and the ". " operator.
- A static method can be invoked without creating an object. Static methods are declared with the "static" keyword.
- Public static methods are accessed by class name and the ". " operator.
- A static method can only access static variables and other static methods if another object of the class has been explicitly created.
- Static methods can be used when creating subtasks in the main method, commonly used for test methods.
- A main method can be added to a class to test it.
- The Java Math class contains static methods for mathematical functions.
- A wrapper class is capable of converting primitive variables to instance variables.
- Decomposition is breaking a task into subtasks, usually via private methods.
- Methods that test other methods are called drivers.
- Bottom-up testing requires a method to be tested before any method that calls it.
- A stub is a method implemented in a simplified form so that other methods that call it can be tested. Alternative to bottom-up testing.
- Overloading occurs when a method has the same name but a different signature
- A method signature is a combination of the method name and the parameter list.
Arrays
- An array is an object used to store multiple values in a single variable.
- An array element is a single value within an array.
- An index of an array is an element's location number within an array, accessed by
arr[index]
. - Arrays are declared using
Base_Type[] Array_Name = new Base_Type[Length];
. - "Length" is a final public instance variable that can also access the length of an array.
- Arrays can be iterated through with a for-each loop or a regular for loop.
- A method can return an array.
- The
=
and==
operators behave the same way with arrays as they do with other objects. - Methods can use arrays as parameters.
- A selection sort algorithm is not the most efficient. The
java.util
package has a class called Arrays with a more efficient sort method. - Selection sort is a sorting algorithm that repeatedly finds the smallest unsorted item and swaps it with the first unsorted item.
- The algorithm stops when only one unsorted item is left, guaranteed to be the largest item in the array.
- A searching algorithm finds a specific item in an array.
- Sequential search is a searching algorithm that looks through each item in an array in order.
- A multidimensional array is an array of arrays.
- An array with more than one index is always a multidimensional array.
- Multidimensional arrays can be method parameters and return values.
- A 2D array has two indexes, accessed by
arr[rowIndex][columnIndex]
. - In 2D arrays, the first index represents rows, and the second index represents columns.
- 2D arrays can be iterated through using nested for loops.
- A ragged array is a 2D array where the rows have different lengths.
Inheritance, Interfaces, Abstract Classes, Exceptions, and Recursive Methods
- Inheritance defines general classes along with specialized classes that inherit features of the general class and additional features.
- Subclasses inherit all instance variables and public methods from the superclass, but not private methods.
- The "super" keyword is necessary in the subclass, and must be the first statement in the subclass constructor:
super();
- Constructors cannot contain both "super" and "this" and super can also call a base class method that has not been overridden.
- An interface consists of method headers and signatures and may have constant variables, but provides no definition for methods. The keyword "implements" is used in a class header.
- An abstract class can provide both concrete methods and abstract methods (methods with no definition), declared by the keyword "abstract".
- An exception is an abnormal condition that arises in a code sequence at run time, used to handle errors with a try-catch block or by throwing a new exception:
throw new Exception
. - A recursive method calls itself, consisting of a base case and a recursive case.
- The base case is a defined execution, and the recursive case calls itself with a modified argument.
- Examples of recursive methods: input validation, binary search, and merge sorts.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.