Both languages support inheritance from a single class, but C++ supports multiple inheritance as well. This means that a single C++ class can extend more than one base (or super) class.
Java supports interfaces, which generally addresses the lack of multiple inheritance support, since multiple interfaces can be implemented in a single Java class. An interface would be similar to a virtual base class in C++ (where all methods -- functions -- are abstract and must be implemented by the inheriting class).
Added:
Other answers correctly mention multi-level inheritance support for both C++ and Java. Classes can inherit from inherited classes any number of levels, as long as each parent is defined as public or protected (and not private or final).
How many types of Inheritnace are there in java and c++?
Java and C++ both support single and multilevel inheritance.
C++ allows multiple inheritance (i.e. a class inheriting from more than one superclasses). Java does not support multiple inheritance because of the various complexities involved.
for e.g., if both the superclasses have a function of the same name, say func() and if we call this method from an object of the sub-class, there is a conflict situation wherein it cannot be resolved as to which super-class' func() to call.
Reply:There are as follows:
single inheritance,multiple,multilevel,hirerchi... in c++ and java.
hope you got ur answer tc
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment