AP Computer Science Midterm Practice EXAM- Java Basics, Arrays QUESTIONS WITH ANSWERS 2023
AP Computer Science Midterm Practice EXAM- Java Basics, Arrays QUESTIONS WITH ANSWERS 2023 Class - ANSWER Java code as a template for an Object (this is abstract code not tied to any specific instance of the object) Instance - ANSWER One object made from the class template (has own instance variables, methods, identity, etc.) Instance Variable - ANSWER variables used to maintain the state of an instance (persistent) Constructor - ANSWER code that is run when you use the new keyword Method - ANSWER code to respond to a message Public variable - ANSWER In a class, anything marked as "public" can be accessed by any client. Private Variable - ANSWER Anything marked "private" can only be accessed inside the class code. Are instance variables public or private? - ANSWER instance variables are private Are constructors and methods public or private? - ANSWER constructors are public methods are public What is a mutator? - ANSWER A setter What is an accessor? - ANSWER A getter Do getters or setters return something? - ANSWER Getters What does a "Public String toString()" do? - ANSWER Does NOT print anything - just creates a String with "state" information toString() example - ANSWER public String toString () { String str; str ="Name: " + name + "n" + "id: " + id + "n" + "Test 1: " + test1 + "n" + "Test 2: " + test2 + "n" + "Test 3: " + test3 + "n" + "Average: " + getAverage(); return str; } makes a new string variable, sets it to variables in the element, and returns it. Object - ANSWER a programming construction that manages its own data and responds to messages from other objects: State - ANSWER describes its current condition (properties, nouns) Behavior - ANSWER describes what it (object) can do (actions, responses, verbs) Identity - ANSWER differentiates one instance from another (like an id number or location in memory) Class (OOP Definition #2) - ANSWER The code you write Defines an object's "state" (as variables) Defines an object's "behavior" (as methods, i.e. functions) "template" or "mold" for creating new objects Tells Java "how" to create an object Instance (OOP Definition #2) - ANSWER Instance = A single actual object "created" based on the template (the class) - the data+code that is actually stored in memory Maintains own "state" Exhibits own "behavior" Maintains own "identity" Two instances, like two cookies made from the same cookiecutter, are still different Referenced with the new keywor
Written for
- Institution
- AP Computer S
- Course
- AP Computer S
Document information
- Uploaded on
- February 8, 2024
- Number of pages
- 5
- Written in
- 2023/2024
- Type
- Exam (elaborations)
- Contains
- Questions & answers
Subjects
-
ap computer science midterm practice exam j
-
ap computer science midterm practice exam java