-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface
63 lines (43 loc) · 1018 Bytes
/
interface
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
import java.util.*;
interface test{
void square(int number);
}
class Arithmetic implements test{
public void square(int number) {
int square = number*number;
System.out.println("The square is: " + square);
}
}
public class ToTestInt {
public static void main(String args[]) {
Arithmetic num1 = new Arithmetic();
num1.square(5);
}
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//new problem
import java.util.*;
interface A {
int a = 5;
int b = 7;
void meth1();
void meth2();
}
class MyClass implements A{
public void meth1(){
int sum = a+b;
System.out.println("the sum is: " + sum);
}
public void meth2(){
int diff = a-b;
System.out.println("the difference is: " + diff);
}
}
public class PlusMinus{
public static void main(String args[])
{
MyClass obj1 = new MyClass();
obj1.meth1();
obj1.meth2();
}
}