forked from badal74/java-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion46.java
More file actions
50 lines (38 loc) · 1008 Bytes
/
Copy pathQuestion46.java
File metadata and controls
50 lines (38 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//How to create Multiple class in java Program
import java.io.*;
// Class 1
// A Grand parent class in diamond
class GrandParent {
void fun() {
// Print statement to be executed when this method is called
System.out.println("Grandparent");
}
}
// Class 2
// First Parent class
class Parent1 extends GrandParent {
void fun() {
// Print statement to be executed when this method is called
System.out.println("Parent1");
}
}
// Class 3
// Second Parent Class
class Parent2 extends GrandParent {
void fun() {
// Print statement to be executed when this method is called
System.out.println("Parent2");
}
}
// Class 4
// Inheriting from multiple classes
class Test extends Parent1, Parent2 {
// Main driver method
public static void main(String args[]) {
// Creating object of this class i main() method
Test t = new Test();
// Now calling fun() method from its parent classes
// which will throw compilation error
t.fun();
}
}