Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Why does java doesnot support multiple inheritance?

Answer Posted / deep

Multiple inheritance Oops i think diamond problem..


class A {
public void x() {
System.out.println("Hello");
}

class B extends A {
public void x() {
System.out.println("Hello");
}

class C extends A {
public void x() {
System.out.println("Hello");
}

// Main class
class AB extends B,C // Remember this is not possible in java, a class can extend only one class in java..
{
public static void main(String args[]) {

AB a = new AB();
a.x(); // compiler gets confused whom should i call.. which methods should i invoke since both methods has same name i.e public void x(), complier get scared and raise an error of ambiguity
}
}

To avoid this type of situation, designers of java decided that a class can extends only one class so there would be no ambiguity of methods.. and to over come this issue they added interface..

class can implements n number of interface but can extend only one class.. a interface can extends n number of interface..

Variables declared inside interface are by default,, static and final.. and methods are abstract i.e unimplemented methods, that doesn't have body.. methods of interface are by default abstract and public..

you can make interface public or depends on your requirement.. if you want a interface to access outside of another package better make it public cause non public classes are confined within same package..

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How is a structure different from array ?

992


Why singleton pattern is better than creating singleton class with static instance?

953


What is java reflection?

920


What is the difference between class forname and new?

944


What isan abstract class and when do you use it?

1503


Why string is immutable or final in java

1027


What is the disadvantage of synchronization?

966


What is == in java?

960


How can we create an immutable class in java?

1017


What is meant by collection in java?

1006


Write a program to find maximum and minimum number in array?

938


Assume a thread has lock on it, calling sleep() method on that thread will release the lock?

1043


What is the difference between import java.util.date and java .util?

1003


how to write a program for sending mails between client and server

2021


Is java code slower than native code?

1002