-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinheritence.java
69 lines (57 loc) · 1.84 KB
/
inheritence.java
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class A {
void show(){
System.out.println("show");
}
}
interface B{
void show1();
}
class C extends A implements B {
public void show(){
System.out.println("show");
}
public void show1(){
System.out.println("show1");
}
}
public class inheritence {
public static void main(String[] args){
C c = new C();
c.show();
c.show1();
}
}
/*
* Approach:
Problem:
The problem involves understanding inheritance and interface implementation in Java.
Preface:
The program defines a class A with a method show(), an interface B with a method show1(), and a class C that extends A and implements B.
Logic:
Class A defines a method show() that prints "show".
Interface B defines a method show1() without implementation.
Class C extends A and implements B.
Class C overrides the show() method from A and provides its implementation to print "show".
Class C also implements the show1() method from interface B and provides its implementation to print "show1".
In the main method:
An instance of class C is created.
The show() method of class C is called, which prints "show".
The show1() method of class C is called, which prints "show1".
Pseudocode:
1. Define class A with a method show() that prints "show".
2. Define interface B with a method show1().
3. Define class C that extends A and implements B.
4. Override the show() method in class C to print "show".
5. Implement the show1() method in class C to print "show1".
6. In the main method:
- Create an instance of class C.
- Call the show() method of class C to print "show".
- Call the show1() method of class C to print "show1".
Time Complexity:
Method invocation: O(1)
Output:
The program will output:
show
show1
This is because the show() method of class C will print "show", and the show1() method of class C will print "show1".
*/