You should have put these on the very beginning. The video of packages also. This helps while making and arranging files while making notes according to the topic. In java I find very difficult how to arrange and make notes in Java for different topics. Do each class we have to make different java file then why multiple class concept is used.
public class Main{ public static void main(String[] args) { SciCalc obj = new SciCalc(); System.out.println(obj.add(8, 3)); System.out.println(obj.mult(8, 3)); System.out.println(obj.sub(4, 9)); System.out.println(obj.div(4, 9)); System.out.println(obj.powered(7, 2)); C letter = new C(); letter.toString(); new B(); } } class A{ public A(){ System.out.println("Hello from A"); } } class B extends A{ public B(){ super(); System.out.println("Hello from B"); } } class C extends B{ public C(){ super(); System.out.println("Hello from C"); } } class Calc{ public int add(int n1, int n2){ return n1 + n2; } public int sub(int n1, int n2){ return n1 - n2; } } class Advanced extends Calc{ public int mult(int n1, int n2){ return n1 * n2; } public int div(int n1, int n2){ return n1 / n2; } } class SciCalc extends Advanced{ public double powered(int n1, int n2){ return Math.pow(n1, n2); } }
You should have talked about how C++ solved this ambiguity problem, For anyone who is curious, C++ and other languages which support multiple parents in inheritence, uses function overriding to call the derived class method and then inside there you can use the method of A, B, or both, and include your derived class logic too inside it. This will look like, class AB extends A, B{ func(){ A::func(); B::func(); // your logic here } }
@@disc127 I'm not being cocky, I have no knowledge on C++ and I just started learning java 15 days before. I just googled. Its good to know the ifs and hows of multiple languages but you are correct he doesn't have to talk abt C++.
Hii, I have a doubt plz someone reply and resolve If there is a same method in both the parent classes then it will create ambiguity. Even if there are no any same methods in both the parent classes then also it is giving error? WHAT IS THE REASON BEHIND IT?
Because multiple inheritance is not possible because of the constructors in class not because of the same methods. That is the reason we don't have constructor in interfaces.
My Question: Can method overloading solve this ambiguity problem? Example class Mobile { brand; price; network; public void call() { print("Calling...") } } class SmartPhone { schoolContacts; // ← a database of my networks at school churchContacts; public void call(String schoolContacts) { // ← method overloading print("Calling..." + name of the person I am calling) } public void call(String churchContacts) { print("Calling..." + name of the person I am calling) } } // multiple inheritance public class Apple extends to SmartPhone, Mobile // assuming this syntax works { public static void main(String a[]) { // assuming I create the objects using appropriate classes person1.call() classmate2.call(schoolContacts) coordinator.call(churchContacts) } }
abey gadde, sir bhi voi bholra hey, java mey multiple inheritance kyu naye hota hey and he is explaining the reason behind it, agar english naye atta tho aur eek channel dekhlena, don't comment before listening the full video
please keep making such courses... so glad that i discovered a creator like you...
You should have put these on the very beginning. The video of packages also. This helps while making and arranging files while making notes according to the topic. In java I find very difficult how to arrange and make notes in Java for different topics. Do each class we have to make different java file then why multiple class concept is used.
public class Main{
public static void main(String[] args) {
SciCalc obj = new SciCalc();
System.out.println(obj.add(8, 3));
System.out.println(obj.mult(8, 3));
System.out.println(obj.sub(4, 9));
System.out.println(obj.div(4, 9));
System.out.println(obj.powered(7, 2));
C letter = new C();
letter.toString();
new B();
}
}
class A{
public A(){
System.out.println("Hello from A");
}
}
class B extends A{
public B(){
super();
System.out.println("Hello from B");
}
}
class C extends B{
public C(){
super();
System.out.println("Hello from C");
}
}
class Calc{
public int add(int n1, int n2){
return n1 + n2;
}
public int sub(int n1, int n2){
return n1 - n2;
}
}
class Advanced extends Calc{
public int mult(int n1, int n2){
return n1 * n2;
}
public int div(int n1, int n2){
return n1 / n2;
}
}
class SciCalc extends Advanced{
public double powered(int n1, int n2){
return Math.pow(n1, n2);
}
}
I think multiple inheritance is supported by interfaces in java.......how and why??
i think due to abstract method in the interface
You should have talked about how C++ solved this ambiguity problem,
For anyone who is curious, C++ and other languages which support multiple parents in inheritence, uses function overriding to call the derived class method and then inside there you can use the method of A, B, or both, and include your derived class logic too inside it. This will look like,
class AB extends A, B{
func(){
A::func();
B::func();
// your logic here
}
}
why should he talk abt c++ in a video for java u dont have to be so cocky
@@disc127 I'm not being cocky, I have no knowledge on C++ and I just started learning java 15 days before. I just googled. Its good to know the ifs and hows of multiple languages but you are correct he doesn't have to talk abt C++.
Great class
What about using default method of interfaces from java8 and calling them using interface.super.method..
Very nice sir
Is this also known as Diamond Problem?
Not exactly, the diamond problem is when B and C are extending from A and then again D is trying to extend from both B and C
Master 😁
End twist 😂
Hii, I have a doubt plz someone reply and resolve
If there is a same method in both the parent classes then it will create ambiguity. Even if there are no any same methods in both the parent classes then also it is giving error?
WHAT IS THE REASON BEHIND IT?
As of your code.. The same method name problem can be solved by METHOD OVERLOADING where as the problem could be in your object creation.
Because multiple inheritance is not possible because of the constructors in class not because of the same methods. That is the reason we don't have constructor in interfaces.
👍
My Question: Can method overloading solve this ambiguity problem?
Example
class Mobile
{
brand;
price;
network;
public void call() {
print("Calling...")
}
}
class SmartPhone
{
schoolContacts; // ← a database of my networks at school
churchContacts;
public void call(String schoolContacts) { // ← method overloading
print("Calling..." + name of the person I am calling)
}
public void call(String churchContacts) {
print("Calling..." + name of the person I am calling)
}
}
// multiple inheritance
public class Apple extends to SmartPhone, Mobile // assuming this syntax works
{
public static void main(String a[]) {
// assuming I create the objects using appropriate classes
person1.call()
classmate2.call(schoolContacts)
coordinator.call(churchContacts)
}
}
If there is problem , lets remove the feature instead of finding solution.🤣🤣
They will be happy 🤣🤣🤣🤣
gadde multiple inheritances nahi hota hai java me
abey gadde, sir bhi voi bholra hey, java mey multiple inheritance kyu naye hota hey and he is explaining the reason behind it, agar english naye atta tho aur eek channel dekhlena, don't comment before listening the full video