+ 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();

13th Jul 2016, 6:35 AM
MohammadTaghi Kavoosi
MohammadTaghi Kavoosi - avatar
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)
16th Jul 2016, 3:42 PM
Omkar Deokar
Omkar Deokar - avatar
+ 2
Dog is a dog object, cat is a cat object, they're just referencing the Animal Class.
13th Jul 2016, 6:47 AM
James
James - avatar
+ 2
Cat and Dog classes are subclasses of the class Animal.
13th Jul 2016, 7:26 AM
Diether Dayondon
Diether Dayondon - avatar
+ 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;
22nd Feb 2020, 1:36 PM
Ragavi Madhu
+ 1
Both cat and Dog are subclasses of Animal class
12th Aug 2016, 7:59 AM
Joyx Kish
Joyx Kish - avatar
+ 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.
3rd Jan 2017, 5:36 PM
Sai Saing Hmine Tun
Sai Saing Hmine Tun - avatar
+ 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"; } };
21st Sep 2020, 8:46 PM
OjeifoIduma
0
James is correct...
16th Jul 2016, 5:17 PM
Prashant Sharma
Prashant Sharma - avatar
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.
10th Aug 2016, 5:37 AM
Pratyush Ranjan Sen Sarma
Pratyush Ranjan Sen Sarma - avatar
0
They are subclassed to the class animal
17th Aug 2016, 8:45 PM
Wallace Scott
0
belong to animal but run cat/dog methods
11th Feb 2017, 2:29 AM
Icedub
Icedub - avatar
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;
21st Sep 2020, 8:37 PM
OjeifoIduma
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; }
21st Sep 2020, 9:01 PM
OjeifoIduma
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; }
21st Sep 2020, 9:16 PM
OjeifoIduma
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;
21st Sep 2020, 9:23 PM
OjeifoIduma
0
class Person { public: virtual void hello() { cout << "Person says hello"; } }; class Student : public Person { public: void hello() { cout << "Student says hello"; } };
23rd Feb 2021, 5:19 AM
changa Hettiarachchi
changa Hettiarachchi - avatar