+ 4
which class this objects belongs to?
i don't understand which class these objects belong's to? Animal or dog/cat..? Animal a = new Dog(); Animal b = new Cat();
16 odpowiedzi
+ 3
left part of '=' declares reference to the class (animal in this case)
while the right part allocates memory using 'new' keyword for that object of respective class (dog and cat in this case)
+ 2
Dog is a dog object, cat is a cat object, they're just referencing the Animal Class.
+ 2
Cat and Dog classes are subclasses of the class Animal.
+ 2
Fill in the blanks to declare ''Dog'' and ''Cat'' objects, and two ''Pet'' pointers pointing to the ''Dog'' object and the ''Cat'' objects, respectively.
answer
Dog dogObj; Cat catObj;
Pet
*
pet1 =
&
dogObj;
Pet* pet2 =
&
catObj;
+ 1
Both cat and Dog are subclasses of Animal class
+ 1
Animal is the super that's why u see this right.
In your sentence, subclass of Dog and Cat are trying to cast to Animal(Super Class). Because these two have every methods and variables that super class has(except which are declared with private modifier), it's possible to cast implicitly.
Otherwise, if u try to cast Animal(Super class) to subclass, you must cast it explicitly.
For example,
Animal a = new Dog(); // It's right
Dog b = new Animal(); // It will throw wrong
Dog b = (Dog)new Animal(); // But it is right
Because super class won't have every methods and variables that its subclasses have.
+ 1
Fill in the blanks to declare a ''Person'' class, with the ''hello()'' virtual function, and then declare a ''Student'' class that inherits from the ''Person'' class and overrides its ''hello()'' virtual function.
Answer:
class Person {
public:
virtual
void hello() {
cout << "Person says hello"; }
};
class student: public person {
public:
void hello() {
cout << "Student says hello"; }
};
0
James is correct...
0
a and b both are the objects of Animal class..... Where Dog and Cat are the subclasses of Animal.
Both objects a & b are refering to Animal class.
0
They are subclassed to the class animal
0
belong to animal but run cat/dog methods
0
Fill in the blanks to declare ''Dog'' and ''Cat'' objects, and two ''Pet'' pointers pointing to the ''Dog'' object and the ''Cat'' objects, respectively.
Answer:
Dog dogObj; Cat catObj;
Pet
pet1 = &
dogObj;
Pet* pet2 = &
catObj;
0
Fill in the blanks to declare two integer variables ''x'' and ''y'', and pass them to the previously created ''sum()'' function. Print the result to the screen.
Answer:
int main()
{
int x = 7;
int y = 11;
cout << sum (x, y) << endl;
}
0
Drag and drop from the options below to declare a template function with two arguments. The function returns the sum of its arguments. The arguments are of template type T.
Answer:
template<class T>
T sum( Ta, T b)
{
return a + b;
}
0
Fill in the blanks to declare two double variables, and pass them to the template ''sum'' function. Print the result to the screen.
Answer:
int main()
{
double a = 4.3;
double b = 7.2;
cout << (a, b) << endl;
0
class Person {
public:
virtual
void hello() {
cout << "Person says hello"; }
};
class
Student :
public
Person {
public:
void hello() {
cout << "Student says hello"; }
};