All AP Computer Science A Resources
Example Questions
Example Question #2 : Program Design
What is the value of the string kitchen after the following code is run?
- class home
- {
- public:
- home(string);
- void searchhome();
- int buyhome();
- private:
- string kitchen();
- };
- home::home(string c)
- {
- kitchen=c;
- }
- int main()
- {
- str=’big’;
- home(str);
- }
Possible Answers:
str
'small'
'big'
c
void
Correct answer:
'big'
Explanation:
The constructor here in line 4 of the class definition is where it gets tricky. In the initialization of the constructor, we note that the input is a string.
Going down to line 10, to where the constructor function is defined, we see that a constructor with an input of c, which is defined as a string, will set the value of kitchen to c.
Finally, going down to our main code, we see that the value of the constructor in main is 'big', defined in str.
So kitchen='big'.
All AP Computer Science A Resources
Popular Subjects
GMAT Tutors in Washington DC, Reading Tutors in Los Angeles, Biology Tutors in Denver, ISEE Tutors in Los Angeles, MCAT Tutors in Washington DC, ISEE Tutors in Philadelphia, Spanish Tutors in Boston, Calculus Tutors in Miami, SSAT Tutors in Phoenix, English Tutors in New York City
Popular Courses & Classes
SSAT Courses & Classes in New York City, SSAT Courses & Classes in Washington DC, ACT Courses & Classes in San Diego, MCAT Courses & Classes in Houston, SSAT Courses & Classes in Houston, Spanish Courses & Classes in Phoenix, SAT Courses & Classes in Chicago, MCAT Courses & Classes in San Francisco-Bay Area, SSAT Courses & Classes in San Francisco-Bay Area, ISEE Courses & Classes in Dallas Fort Worth
Popular Test Prep
SAT Test Prep in New York City, SSAT Test Prep in Washington DC, GRE Test Prep in Denver, SSAT Test Prep in San Francisco-Bay Area, ISEE Test Prep in Denver, ISEE Test Prep in Phoenix, MCAT Test Prep in Houston, SAT Test Prep in Boston, ACT Test Prep in San Diego, GMAT Test Prep in Dallas Fort Worth