CSIT-112 Midterm Study Guide PDF
Document Details
Uploaded by CourteousSatire2150
Montclair State University
Jesse Parron
Tags
Related
- OOP - JAVA Object-Oriented Programming PDF
- Topic 1.6 Running Program with Objects PDF
- CS0070 Object-Oriented Programming Module 1 PDF
- Object Oriented Programming (2nd Year 1st Sem) PDF
- Introduction to Java Programming and Data Structures (2019) by Y. Daniel Liang - PDF
- CSC435: Object-Oriented Programming - Topic 3 - Basic Class Concept PDF
Summary
This study guide covers the topics of object-oriented programming concepts using Java, focusing on topics like classes, inheritance, and polymorphism. It is presented as a question and answer format suitable for exam preparation.
Full Transcript
CSIT-112 Midterm Study Guide - Remember that this midterm will be fully comprehensive of the entire course. Fill it out and familiarize yourself with all concepts. - Filled in by Jesse Parron Lecture 1: 1. What...
CSIT-112 Midterm Study Guide - Remember that this midterm will be fully comprehensive of the entire course. Fill it out and familiarize yourself with all concepts. - Filled in by Jesse Parron Lecture 1: 1. What is a class? And what does it represent? a. A class is a blueprint of an object. b. The class represents the concept of an object 2. What is inheritance? a. Inheritance is a fundamental object-oriented design technique used to create and organize reusable classes i. Which is cheaper than creating new classes from scratch b. It is the process in which a new class is derived from an existing one c. The new class automatically “inherits” the variables and methods of the original class 3. The original class can be referred to in three different ways, what are they? a. Parent class b. Superclass c. Base class 4. The derived class can be referred to in two different ways, what are they? a. Child class b. subclass 5. How do we depict inheritance relationships a. Using a solid arrow pointing to the parent class 6. What type of relationship does proper inheritance create? a. It is an is-a relationship 7. What are the benefits of inheritance? a. Software reuse - capitalize on already existing software components, and less space 8. What is the reserved word in java used to establish a inheritance relationship? a. extends 9. What are the three visibility modifiers? a. Public b. Protected c. private 10. What do each of the visibility modifiers do? a. The protected modifier allows a child class to reference a variable or method in the child class. It provides more encapsulation than public visibility, but is not as tightly encapsulated as private visibility b. Public modifier -> visible everywhere c. Private modifier -> member can be accessed only by its own class d. Protected modifier -> member can only be accessed within its own package and, in addition, by a subclass of its class in another package 11. What does super do? a. can be used to refer to the parent class, and often Is used to invoke the parent's constructor 12. What is overriding? a. A child class can override the definition of an inherited method in favor of its own 13. What is overloading? a. Overloading deals with multiple methods with the same name in the same class, but with different signatures 14. What does the final modifier do? a. The method cannot be overridden Lecture 2 15. What is it called when two children are from the same parent? Although they are from the same parent, what is different between them? a. Siblings b. Siblings have the same characteristics passed down from their parents (Inheritance), but do not hold the relationship of inheritance between each other as they are not derived from one another 16. Where should common features be established in a class hierarchy? why? a. As far up as they can be 17. When we say inheritance is transitive, what does that mean? a. inherited traits are continuously passed down. 18. Why do we typically override the toString() method? a. We typically override the inherited toString() method so we can get our own string representation 19. What does the equals method do? a. The definition of the equals method provided by the Object class returns true if the two object references actually refer to the same object 20. What is a java interface? Try to be thorough with your answer a. is a collection of abstract methods and constants b. is used to establish a set of methods that a class will implement 21. What is an abstract method? a. is a method header without a method body b. An abstract method can be declared using the modifier abstract, but because all methods in an interface are abstract, usually it is left off 22. What is the reserved word that allows us to use interfaces in our class header? a. Interface and implements 23. What is an abstract class? a. is a placeholder in a class hierarchy that represents a generic concept b. An abstract class cannot be instantiated Lecture 4 24. What does polymorphism mean? a. to have many forms 25. What does polymorphism allow us to do? a. allows a message to be displayed in more than one form b. allows you to define one interface and have multiple implementations 26. What can happen to a method if it is called through a polymorphic reference? a. The method called through a polymorphic reference can change from one invocation to the next 27. What are the two types of polymorphism? a. Compile time b. runtime 28. What is binding? a. if the reference obj is polymorphic, it can refer to different types of objects at different times b. So if we loop that method or call it more than once, we may be calling a different version of doIt each time it is invoked c. At some point, this invocation is bound to the definition of the method that it invokes 29. What is dynamic binding/late binding? a. the decision cannot be made until run time 30. Review the examples of polymorphism in the slides (do not write anything here) Lecture 5 31. Explain polymorphism via interfaces a. Polymorphism works the same way as it does prior but remember interface reference variable can be used to refer to any object of any class that implements that interface 32. What does casting do? When can we use it? a. We can cast the appropriate reference. b. If we know in a particular situation that such an invocation is valid, we can cast the object into the appropriate reference so that the compiler will accept it 33. What is sorting? a. is the process of arranging a list of items in a particular order 34. What is the strategy we use for selection sort? a. 35. How do we swap the values in selection sort? (use what i gave you in the slides, its only three lines. Not actual code) a. 36. What is the comparable interface? a. interface is built into java and apart of the java.lang package. b. We can import the Comparable interface using java.lang.Comparable. c. The Comparable interface is used to compare an object of the same class with an instance of that class. d. It allows objects of a class to be compared to each other, typically for sorting purposes. Lecture 6. 37. What does the compareTo method do? a. we can compare two inputs against each other b. What does it return if input1 < input2 i. Negative value c. What does it return if input1==input2 i. 0 d. What does it return if input1>input2 i. Positive value 38. What is the strategy for insertion sort? a. pick any item and insert it into its proper place in a sorted sublist b. repeat until all items have been inserted Lecture 7 39. What is a search pool? a. A search pool is essentially a group of items 40. Searching is the process of what? a. is the process of finding a target element within a group of items called the search pool. 41. Explain linear search and the steps used to conduct it. Review the examples in the slides a. 42. Does an array need to be sorted for binary search? a. Yes 43. Explain binary search and the steps used to conduct it. Review the example in the slides. a. In Binary search instead of starting at the beginning or end of the array, we can start at the middle index. b. If the key is at the middle index we finish our search, otherwise the array is essentially split. c. Now we know that if the target is not in the middle index, we can essentially eliminate one of the two sub arrays, since we know the array is sorted. d. If the target is larger than our middle element, we know its in the right subarray e. If the target is smaller than our middle element, we know its in the left subarray Lecture 8 44. What do exceptions represent? a. represent problems or unusual situations that may occur in a program 45. What is an exception? a. is an object that defines an unusual or erroneous situation 46. What is an error? a. is also represented as an object in Java, but usually represents a unrecoverable situation and should not be caught 47. List scenarios that may cause an exception to be thrown a. 48. What happens if our program does not handle the exception when it occurs? a. The program will terminate and produce a message that describes what exception occurred and where it was produced. 49. What happens if an exception is ignored? a. the program will terminate and produce an appropriate message 50. What is the call stack trace? a. The message includes a call stack trace that: i. Indicates the line on which the exception occurred ii. Shows the method call trail that lead to the attempted execution of the offending line 51. What does each line of the call stack trace represent? Like what is the data it gives us? a. The first trace line indicates the method, file, and line number where the exception occurred. The other trace lines, if present, indicate the methods that were called to get to the method that produced the exception 52. What is a try-catch statement? a. The try-catch statement identifies a block of statements that may throw an exception b. First we have a try block: c. 53. What is the try block? i. This block allows you to define a block of code to be tested for errors while it is being executed 54. What is the catch block? a. Allows you to define a block of code to be executed, if an error occurs in the try block 55. What happens if no exception is thrown for the try-catch statement to catch? a. then we continue to process the statements after the try block. 56. Each catch clause is known as what? a. Catch handler 57. What is an exception variable? a. can also be used alongside the getMessage method that returns a string explaining the reason the exception was thrown. 58. What does the getMessage method do? a. returns a string explaining the reason the exception was thrown 59. What does the finally clause do? a. Is a clause that is executed no matter how the try block is exited Lecture 9 60. What is exception propagation? a. If an exception is not caught and handled where it occurs, control is immediately returned to the method that invoked the method that produced the exception. b. If it is not caught there, the exception continues to propagate until the exception is caught or handled or until it is passed out of the main method, which will ultimately terminate the program. 61. What do we extend to define our own exception? a. We Extend the Exceptions class 62. All error and exception classes are descendants of what class? a. Throwable class 63. What is the throwable class? What reserved word does it give us access to? a. is the parent of both Exception and Error classes. b. We can consider Throwable to be the superclass of all errors and exceptions. c. It provides the basis for all descendant classes such as Error and Exception d. Descendants of the throwable class have the ability to use the reserved word throw which is used to start exception propagation. e. Reserved word throw 64. What does the reserved word throw do? a. Start exception propagation b. is used to explicitly throw an exception 65. Explain checked exceptions a. A checked exception must either be caught or must be listed in the throws clause of any method that may throw or propagate it 66. Explain unchecked exceptions a. An unchecked exception does not require explicit handling, though it could be processed that way. It does not require a throw clause. b. The only unchecked exceptions in Java are objects of type RuntimeException or any of its descendants 67. Which exceptions that we have reviewed so far based on the slides are checked? Which exceptions are unchecked? a. ClassNotFoundException b. NoSuchMethodException Lecture 10 68. What is a stream? What are the two types? a. is a sequence of bytes that flow from a source to a destination i. Byte stream - videos, images, audio, non-textual ii. Character stream - textual data, text files 69. What are the three standard I/O streams? a. standard output – defined by System.out b. standard input – defined by System.in c. standard error – defined by System.err 70. Is the IOException checked or unchecked? a. It is a checked exception 71. What is system.in, system.out, and system.err? a. System.in – standard input stream b. System.out – standard output stream c. System.err – standard error stream