Recognizing Class Hierarchy
Help Questions
AP Computer Science A › Recognizing Class Hierarchy
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);
- }
'big'
'small'
str
c
void
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'.
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);
- }
'big'
'small'
str
c
void
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'.
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);
- }
'big'
'small'
str
c
void
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'.
Consider the history of the following popular programming languages:
PHP
Java
Objective-C
Python
Which of the following is the closest ancestor shared by ALL of these languages?
C
Ruby
Lisp
Ada
Smalltalk
Explanation
All of these languages are C-based languages.
- Ruby was invented in 1995, the same year as PHP, so it could not have influenced earlier languages like Objective-C and Python.
- Lisp did influence at least one language, Python, but it did not influence any others.
- Ada directly influenced Java, and because it influenced C, it can be argued that it is an ancestor of these other languages; however, because of this, Ada is not the CLOSEST ancestor.
- Smalltalk influenced Objective-C, but no other languages on this list.
A clue was the answer "Objective-C," which is a strict superset of C that adds Object Orientation.
Consider the history of the following popular programming languages:
PHP
Java
Objective-C
Python
Which of the following is the closest ancestor shared by ALL of these languages?
C
Ruby
Lisp
Ada
Smalltalk
Explanation
All of these languages are C-based languages.
- Ruby was invented in 1995, the same year as PHP, so it could not have influenced earlier languages like Objective-C and Python.
- Lisp did influence at least one language, Python, but it did not influence any others.
- Ada directly influenced Java, and because it influenced C, it can be argued that it is an ancestor of these other languages; however, because of this, Ada is not the CLOSEST ancestor.
- Smalltalk influenced Objective-C, but no other languages on this list.
A clue was the answer "Objective-C," which is a strict superset of C that adds Object Orientation.
Consider the history of the following popular programming languages:
PHP
Java
Objective-C
Python
Which of the following is the closest ancestor shared by ALL of these languages?
C
Ruby
Lisp
Ada
Smalltalk
Explanation
All of these languages are C-based languages.
- Ruby was invented in 1995, the same year as PHP, so it could not have influenced earlier languages like Objective-C and Python.
- Lisp did influence at least one language, Python, but it did not influence any others.
- Ada directly influenced Java, and because it influenced C, it can be argued that it is an ancestor of these other languages; however, because of this, Ada is not the CLOSEST ancestor.
- Smalltalk influenced Objective-C, but no other languages on this list.
A clue was the answer "Objective-C," which is a strict superset of C that adds Object Orientation.