All AP Computer Science A Resources
Example Questions
Example Question #1 : 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:
'small'
str
void
'big'
c
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
LSAT Tutors in San Francisco-Bay Area, Spanish Tutors in Houston, Statistics Tutors in Atlanta, ISEE Tutors in Dallas Fort Worth, Chemistry Tutors in Denver, Reading Tutors in Houston, ISEE Tutors in Miami, Spanish Tutors in Chicago, ACT Tutors in Denver, Math Tutors in Boston
Popular Courses & Classes
GRE Courses & Classes in San Francisco-Bay Area, ISEE Courses & Classes in Chicago, SSAT Courses & Classes in Los Angeles, SAT Courses & Classes in Denver, SSAT Courses & Classes in Denver, ACT Courses & Classes in Dallas Fort Worth, SAT Courses & Classes in Washington DC, ACT Courses & Classes in San Diego, MCAT Courses & Classes in Chicago, GMAT Courses & Classes in Atlanta