Why java Don't Support Multiple interitence

Answer Posted / bhaskar reddy

There is a big reason behind that(java does not support
multiple inheritance). Please go through the following
example.

1. Assume that java is supporting multiple inheritance

class A {

void m1() {
// implement method
}
}

class B {
void m1() {
// implement method
}
}
//As for the assumption (1) the following code will compile

class C extends A,B {

public static void main( String s[]) {

C c = new C();
c.m1();
}
}

Note : In main method i am calling c.m1() method In this
situation which super class m1 method has to call (from A
or B) JVM will confuse.

So our assumtion(1) is wrong .

This is the reason why java does not support multple
inheritance through classes.

Note : This same cocept is applicable for classes.

Is This Answer Correct ?    29 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are nested classes in java?

600


Which data type is a class in java?

569


what is the purpose of "virtual"?

564


please send me hr interview questions in it industry

1657


What is the biggest integer?

543






Explain super keyword in java.

576


Explain the importance of finally block in java?

566


When do we use hashset over treeset?

528


Say you want to store the information about a number of pets in an array. Typical information that you could store for each pet (where relevant) would be • Breed of animal • Animal's name • Its birth date • Its sex • Whether it has been sterilised or not • When it is due for its next inoculation • When it last had its wings clipped For each type of pet (eg. dog, cat or bird) you would typically define a class to hold the relevant data. Note: You do not need to implement these classes. Just answer the following questions. 3.1.1 What would be the advantage of creating a superclass (eg. Pet) and declaring an array of Pet objects over simply using an array of Objects, storing each of the instances of the different pet classes (eg. Dog, Cat or Bird) in it? 3.1.2 Would you define Pet as a class or as an interface? Why? (2) (2)

1343


What is one third plus one third as a fraction?

482


Can we increase array size dynamically in java?

500


Is there any way to find whether software installed in the system is registered by just providing the .exe file? I have tried the following code but its just displaying the directory structure in the registry. Here the code : package com.msi.intaller; import java.util.Iterator; import ca.beq.util.win32.registry.RegistryKey; import ca.beq.util.win32.registry.RootKey; public class RegistryFinder { public static void main(String... args) throws Exception { RegistryKey.initialize(RegistryFinder.class.getResource("jRe gistryKey.dll").getFile()); RegistryKey key = new RegistryKey(RootKey.HKLM, "Software\\ODBC"); for (Iterator subkeys = key.subkeys(); subkeys.hasNext();) { RegistryKey subkey = subkeys.next(); System.out.println(subkey.getName()); // You need to check here if there's anything which matches "Mozilla FireFox". } } }

1347


What do you understand by the term polymorphism?

625


How to compare two strings in java program?

669


Is there any limitation of using inheritance?

568