What is inheritance? Define Public and Private Inheritance. Write an example using C++.?
358642
class Car {\npublic:\nCar();\n~Car();\nvoid Accelerate( float howmuch );\nvoid Brake( float howmuch );\nint Turn( float howmuch );\nint fuel;\n\nprivate:\nint speed;\nfloat accelerate;\nint SubFuel(int qty);\n};\n\nYou should aleady be familiar with the concept of structures (or structs) in C, a structure contains a series of variables which can be used to group data together. A C++ class does much the same thing, except that it not only provides data but also functions to manipulate that data.\nNow let's examine this code line by line. The first line simply says 'I want to define a class called 'Car', the syntax is similar to that used in a struct, except that whenever you wanted to create a variable of type Car you only have to type Car mycar; rather than class Car mycar;. The third line declares all the variables that follow to be 'public'. This means that they can be accessed by any piece of code, for example:\n\nvoid main( void ) {\nCar mycar;\nint fuel;\n\nmycar.Accelerate( 0.5 ); // Note the use of . to access data members and data functions\nfuel = mycar.fuel;// If you had a pointer to a class then you would use ->, as in a struct\n}\n\nNow the forth line is important, it defines a function called 'Car' with no return type. Because this function has the same name as the class it is treated specially, it is called a constructor because whenever a new version of the class is created the constructor is called to initalise the objects data. The fith line is the opposite, because it is the calss name preceded by a ~ symbol it is called the destructor and is automatically called whenever an object is deleted or removed from memory.\nThe next three lines define three member functions, which can be accessed using the '.' method, these have no special meaning and have to be called manually from code (for example on the sixth line of the 'main' example above accelerate is called for the object 'mycar' of type 'Car'). The nineth line declares a meber variable of type int called fuel, this can be treated in much the same way as you treat a struct's member variable.\nThe tenth line is another improtant one, it tells the compiler that the member functions and variables that follow it ar private, meaning that they can only be accessed by the member functions of the class. In this case only the functions Car, ~Car, Accelerate, Brake, Turn and SubFuel would be able to access 'speed' or 'accelerate'. This is also true of the private member function 'SubFuel'. Finally two variables called speed and accelerate and a function calle SubFuel are defined.\n\nYou have seen that a class can contain member variables that can be public or private depending on who you want to be able to access these functions. It is in fact comon to make all member variables private and use functions to Set and Get them because this has the added advantage of enableing you to 'validate' the new data. In addition to public and private data there is also protected data. Protected data is only accessable by the class itself, derivates (see below) of the class and friends of the class. For example, if you had another calss called Driver and you wanted him to be able to access speed then inserting the following code instead of the private block would give driver access to it:\n\nprotected:\nint speed;\nfriend Driver; // make the class 'Driver' a friend, you can also make functions friends\nprivate:\nfloat accelerate;\nSubFuel(int qty);\n\nSo far you have only seen the declaration of the class, you have not seen the implementation of any of the functions. There are two ways to implement the functions, the first is directly into the class - this method is often used if the function is very short:\n\n// A simplified version of the Car class, demonstarting the simple implementation of the Car constructor\nclass Car\n{\npublic:\nCar() {\nfuel = 100;\n}\nprivate:\ni
409206
The short answer, C++ is object-oriented C.\nC# is Microsoft's answer to Java.\n\n\nC++ has classes and objects build into the languge.\n\nC# has no pointers, but does have garbage collection.\n\nI would learn C++ first.
52791
C) ABC, somthing1, something2 must be interface for the expression to be legal.\n\nThough java doesn't supports multiple inheritence for class, an interface can extend as many interface as needed. You can try compiling. But there is also a reason behind it.\nJava does not supports multiple inheritence because in diamond inheritence ( B and C extends A and D extends both B and C) it can cause ambiguity( as two copies of members of A would present in D).\nThis is not so for interface as there can't be ambiguity as all refer to same copy. So Java supports multiple inheritence for Inetrface
23070
In C++, the only difference is that classes by default have private members, while structs by default have public members.  All other things that classes can do (inheritance, virtual methods, etc.), structs can do as well.
12275
Follow this link:\n\nhttp://www.thefreecountry.com/compilers/cpp.shtml\n\n:)
640622
Scope is the visibility of a variable, a method, or a property or other member of a class.  \n\nGood programming style will limit scope of variables as much as possible.  For example, a complex algorigthm might have hundreds of lines of code, dozens of variables, complex calculations etc.  But from the outside, calling the method should be as simple as possible.  \n\nResticting scope makes the use of the object or function easier to use, and also protects the variables use internally from misuse, whether unitentional or otherwise.  \n\nIn most languages, varibles can be:\n public (visible and usable by everyone)\n internal (not visible or usable by anyone outside the method or class)\n protected (only visible or usable by derived classes)\n shared (also called static, shared by all instances of a class or method)
347509
Some good topics:\n\nException Handling\nTemplates\nThe Standard Library\nMultiple Inheritance\n\nA great resource is Thinking in C++ by Bruce Eckel. You can download a free copy of the book from his website here: http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html\n\nAs far as learning Windows programming, the best resource is Programming Applications for Windows by Jeffrey Richter. It is out of print though, so the best way to get it would be via Amazon, EBay, etc. MSDN is also a great source (More as a reference though).\n\nYou should also consider C++/CLI, which is quickly becoming one of my favorite languages. All the power of C++ as well as the power of the .Net framework.
701316
Inner Classes \n\nInner classes let you define one class within another. \n\nThey provide a type of scoping for your classes since you can make one class a member of another class.\n\nJust as classes have member variables and methods, a class can also have member classes.\n\nclass Outer { \n/class Inner { } \n}// End of class \n\nif you compile it,\n%javac Outer.java\n\n\nyou’ll end up with two class files:\nOuter.class\nOuter$Inner.class\n\n\ne.g.\n\nclass Outer { \nprivate int x = 5;\n\npublic void outerMethod() {\nInner in = new Inner();\nin.innerMethod();\n}\n\nclass Inner {\npublic void innerMethod() {\nSystem.out.println("Outer variable x is " + x);\n}\n} \n}// End of class \n\n\nYou can create four different types of inner classes, based upon the how and the where of creation. \nNested top-level classes\nIf you declare a class within a class and specify the static modifier, the compiler treats the class just like any other top-level class. Any class outside the declaring class accesses the nested class with the declaring class name acting similarly to a package. eg, outer.inner. Top-level inner classes implicitly have access only to static variables. There can also be inner interfaces. All of these are of the nested top-level variety.\n\nMember classes\nMember inner classes are just like other member methods and member variables and access to the member class is restricted, just like methods and variables. This means a public member class acts similarly to a nested top-level class. The primary difference between member classes and nested top-level classes is that member classes have access to the specific instance of the enclosing class.\n\nLocal classes\nLocal classes are like local variables, specific to a block of code.Their visibility is only within the block of their declaration. In order for the class to be useful beyond the declaration block, it would need to implement a more publicly available interface.Because local classes are not members, the modifiers public, protected, private, and static are not usable.\n\nAnonymous classes \nAnonymous inner classes extend local inner classes one level further. As anonymous classes have no name, you cannot provide a constructor.
599192
In the object oriented world of thinking you have objects that are made of classes. These classes can be ordered through a special inheritance relationship into hierarchies of parent/child relationships. \n\nUpcasting means taking a reference to an object and changing\nits type to that of any of its parent classes. (for java, add to this list also all the interfaces that any of the parent classes may be implementing)\n\nFor example:\nclass A extends B{\n}\nclass B{\n}\nclass Program{\n\n    .......\n    B b = new B();\n    A a = (A) b; // this is upcasting!\n    .......\n}\n\nUpcasting in java is implicit. This means that you dont need\nthe preceding parenthesis with the upcasting type.\n    A a = b;\nwould have equally worked. This is because you are going from something specific (class B - child) to something more general (class A - parent) and the java compiler can infer this fact by its design.\n\nDowncasting is the opposite:\n    .......\n    A a = new B(); //here you have an object from class B\n                   //referenced to a variable of class A\n                   //Implicit upcasting happens here.\n\n    B b = (B) a; // this is downcasting.\n\nDowncasting must be explicit. If you try to downcast an\nobject to a type that cant be downcasted to, then the compiler will offer protection by giving you an error.\nOtherwise your program would have crashed at runtime.\n\nYou can test with the operator instanceOf whether a \ndowncast is safe.\nexample:\n   if (a instanceOf (B)) { \n        b = (B)a;\n   }\n\nThe problem with this is that it creates a dependency in that segment of code and the type B. If in the future you create sibling to B classes you will have to remember to change all the places where you are checking with "instanceOf" and this can be a try nightmare on a large system.\n\nSo, generally speaking, you want to create code that avoids downcasting. This is not always possible and not always a good idea as there are many cases where explicit downcasting is needed or at least is possible to use without problems. \nAgain generally speaking, you want to create designs that have parts that are as independent, decoupled, reusable, robust, modular, and change adaptive as possible. This is not easy because many of these forces lead you to contradictions. So its all about making choices.\n\nfor an easy visual guide to java have a look at an online tutorial that I have recently added to: http://www.thanassis.com/java/index.htm
24164
I think you are asking in C++. \nYes you can do it. \n\nlet the structure be like this\nstruct base{\n int x;\n};\nHere I want to add the member x is a public this is the difference between class and structure. \n\nConsider the following code segment. \n#include <iostream>\nstruct base{\n        int i;\n};\nstruct inhe : base{\n        int j;\n};\n\nmain(){\n        inhe ob;\n        ob.i=10;\n        ob.j=12;\n        cout<<ob.i<<endl;\n        cout<<ob.j<<endl;\n        return 0;\n}\nOutput :\n10\n12
756121
#include <iostream>\n\nusing namespace std;\n\nchar *yourUsercode = "user";\nchar *yourPasscode = "pass";\n\nint main()\n{\n   string usercode;\n   string passcode;\n\n   cout << "LOGIN:&#92;n&#92;n";\n   cout << "USERCODE:&#92;n";\n   cin >> usercode;\n\n   cout << "&#92;nPASSCODE:&#92;n";\n   cin >> passcode;\n\n   if (usercode == yourUsercode){\n\n      if (passcode == yourPasscode) {\n         cout << "Access Granted&#92;n";\n      } else {\n         cout << "Invalid Passcode&#92;n";\n      }\n\n   } else {\n\n      if (passcode == yourPasscode) {\n         cout << "Invalid Usercode&#92;n";\n      } else {\n         cout << "Access Denied&#92;n";\n      }\n\n   }\n   \n   return 0;\n}
7389
There are many, but if I had to pick one, it's the support for generics. That's much like C++ templates (classes or methods that you can customize what types they work with -and other parameters- the moment you need to use them), only they get compiled into intermediate language only once.
112338
In object-oriented programming languages with multiple inheritance, the diamond problem is an ambiguity that arises when two classes B and C inherit from A, and class D inherits from both B and C. If a method in D calls a method defined in A, which class does it inherit from, B or C?\n\n\n\nIt is called the 'diamond' problem because of the shape of the class inheritance diagram in this situation. Class A is at the top, both B and C separately beneath it, and D joins the two together at the bottom to form a diamond shape.\n\nDifferent programming languages have addressed this problem in different ways:\n\nC# / Java only allow single inheritance, but as a compromise allow the multiple inheritance of interfaces. Interfaces are essentially abstract base classes with all abstract methods and no data members. C# (and other .NET languages that allow interface definition) also allows property defintions to exist at the interface level. \nC++ by default follows each inheritance path separately, so a D object would actually contain two separate A objects, and uses of A's members have to be properly qualified. If the inheritance from A to B and the inheritance from A to C are both marked "virtual" ("class B : virtual A"), C++ takes special care to only create one A object, and uses of A's members work correctly. If virtual inheritance and nonvirtual inheritance are mixed, there is a single virtual A and a nonvirtual A for each nonvirtual inheritance path to A. \nEiffel handles this situation by a select and rename directives, where the ancestors' methods to use in a descendant are explicitly specified. This allows to share the methods of the base class between its descendants or even to give each of them a separate copy of the base class. \nPerl and Io handle this by specifying the inheritance classes as an ordered list. In the above ambiguity, class B and its ancestors would be checked before class C and its ancestors, so the method in A would be inherited through B. \nPython had to deal with this upon the introduction of new-style classes, all of which have a common ancestor, object. Python creates a list of the classes that would be searched in left-first depth-first order (D, B, A, C, A) and then removes all but the last occurrence of any repeated classes. Thus, the method resolution order is: D, B, C, A. \nThe diamond problem is not limited to inheritance. It also seems to arise when header files A, B, C, and D "#include" one another in a diamond as above and separate precompiled headers are created from B and C. If these two precompiled headers are combined, declarations in A are duplicated; the "#ifndef" convention (see the header file article) is ineffective
1059804
yeah, the only difference between the default and public specifier is that default can only be accessed in the same package whereas public can be accessed in other packages too.
781094
Nobody is going to do your homework for you. \n\nIf you're supposed to write code examples that illustrate how two comparable programs might look, then do this. Write some simple programs in C, and then re-write the same program in C++ but put the functions your void main calls in a class and instantiate the class.
98158
OOP languages have extra language features - e.g. encapsulation, polymorphism, and inheritance are object behaviours that don't have a direct procedural equivalent.\n\nFor making setup files, there are commercial solutions like InstallShield, but for free, consider NSIS: http://nsis.sourceforge.net/Main_Page
810227
Compilers. Of course, there is the simple matter of learning the programming language.\n\nHeres a free C++ compiler:\nhttp://www.bloodshed.net/dev/devcpp.html