You are here:

Object Oriented Programming/inheritance and superclass instance

Advertisement


Question
Hi,

With the following snippet, how many objects of type A are created? I know for sure there is one in line #4, but is there another object of type A created in line #5 as well?

Thanks, lzzzz
-------------------------------
class A {};

class B : public A {};

int main() {
A a = new A(); // line #4
B b = new B(); // line #5
}
------------------------------

Answer
Iz,

The easiest way to find the answer is for you to put a print stmt like sprint or AfxMessageBox or whatever will work for your development environment.

Put the print stmt into the class A object constructor method, and you'll see what's happening. This will be more instructive than my just telling you.


Marty Landman, Face 2 Interface Inc.
Webmaster's Bulletin Board: http://bbs.face2interface.com/
Web Installed Formmail: http://face2interface.com/formINSTal

Object Oriented Programming

All Answers


Answers by Expert:


Ask Experts

Volunteer


Marty Landman

Expertise

Available for questions involving packaging, writing and using methods, and generally most object oriented techniques. Conversion from modular (routine based) to OOP (object based) is a pet interest of mine. My language experience in this area is (in order of competence) Perl C++ PHP Visual Basic/ASP Java

Experience

Programmer since 1980, web developer since 1998.

Education/Credentials
M.S. in Computer Science from New York University

©2012 About.com, a part of The New York Times Company. All rights reserved.