100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Exam (elaborations)

AP CSA Code HS section 2 Questions and Answers (Passed with 100%)

Rating
-
Sold
-
Pages
32
Grade
A+
Uploaded on
10-03-2023
Written in
2022/2023

AP CSA Code HS section 2 Questions and Answers (Passed with 100%) What is an object in Java? An object is something that contains both state and behavior. Which of the following best describes the relationship between a class and an object? A class definition specifies the attributes and behavior of every object that will be made. Every class definition has each of the following EXCEPT A name Defined attributes Defined behaviors to manipulate the state of the objects Defined objects as copies of the class Defined objects as copies of the class Consider this class definition of a Pineapple. public class Pineapple { private boolean isRipe; private String color; private double weight; // Rest of class goes here } When we use this class to create Pineapple objects, which of the following is guaranteed to be true? Every Pineapple object will have the same attributes. What is a constructor in Java? A constructor allows us to create a new instance of a class, usually initializing instance variables. Refer to the Card class shown below. public class Card { private String suit; private int value; //13 values for each suit in deck (0 to 12) public Card (String cardSuit, int cardValue) { /* implementation */} // Rest of the class goes here } Which of the following is the correct /* implementation */ code for the constructor in the Card class? suit = cardSuit; value = cardValue; public class Shark { // Attributes private String habitat; private int age; public Shark(String region, int sharkAge) { habitat = region; age = sharkAge; } } Which of the following choices is a formal parameter of the constructor? sharkAge What is the purpose of overloading a class' constructor? It allows the user to set the values of different combinations of the instance variables when the object is created. Which of the following is NOT part of the constructor signature? Which instance variables are initialized Which of the following is NOT a valid way to overload this constructor? For brevity, only the signature is given. Pineapple Pineapple(String color) a. Pineapple Pineapple() b. Pineapple Pineapple(String color, int age) c. Pineapple Pineapple(int age, String species) d. Pineapple FancyPineapple(String color, int age) Pineapple FancyPineapple(String color, int age) What is the importance of the null value? null allows a reference variable to be empty and not hold any memory address. A reference variable holds a special value. What is this special value? The memory address of an object Consider this code snippet that uses a class called Rectangle. int roomHeight = 40; int roomWidth = roomHeight * 3; Rectangle room = new Rectangle(roomHeight, roomWidth); Which of the following is a reference variable? room roomHeight roomWidth Rectangle room What does it mean to be a client of a class? Being a client of a class means that we can use its methods and functionality without necessarily understanding how it works. Suppose a program is a client of the Player class. Here is a snippet of code contained in the program Player firstPlayer = new Player("Karel", "Warrior", "Mote Prime", 90); Looking at the documentation of the class, you find the signature for the constructor, shown below. Player Player(String name, String role, String location, int health); Where would you find the formal parameters? In the program. In the documentation. In the library. Both the program and the documentation contain formal parameters. In the documentation. You are using a class as a client. What would you need to know in order to create an object of the class you intend to use? You need to know the formal parameters in order to pass in actual parameters. What is an instance method? An instance method is a piece of code called on a specific instance (an object) of the class. It is called with a receiver object. Which of the following is a correctly written method for the class below? public class Timer { private int startMin; private int length; public Timer(int minute, int duration) { startMin = minute; length = duration; }

Show more Read less
Institution
AP CSA Code HS
Course
AP CSA Code HS











Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
AP CSA Code HS
Course
AP CSA Code HS

Document information

Uploaded on
March 10, 2023
Number of pages
32
Written in
2022/2023
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
BrilliantScores Chamberlain College Of Nursng
View profile
Follow You need to be logged in order to follow users or courses
Sold
2841
Member since
4 year
Number of followers
2234
Documents
16200
Last sold
23 hours ago
latest updated documents, correct, verified & graded A study materials

get bundles, documents, test banks, case studies, shadow health's, ATIs, HESIs, study guides, summary, assignments & every kind of study materials.

3.8

776 reviews

5
388
4
117
3
117
2
37
1
117

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions