-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path63_Constructor8.java
More file actions
56 lines (48 loc) · 1.36 KB
/
63_Constructor8.java
File metadata and controls
56 lines (48 loc) · 1.36 KB
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
/*
* Program for copying value with constructor taking input from user
*/
package javaprograms;
import java.io.*;
/**
*
* @author Geeky Keshav
*/
public class Constructor8
{
static int num1;
static int num2;
int add;
Constructor8(int n1, int n2)
{
num1=n1;
num2=n2;
}
Constructor8()
{
}
void disp()
{
add=num1+num2;
System.out.println("Addition of these numbers is: "+add);
}
public static void main(String [] args)throws Exception
{
DataInputStream obj=new DataInputStream(System.in);
System.out.print("Enter first number: ");
num1=Integer.parseInt(obj.readLine());
System.out.print("Enter second number: ");
num2=Integer.parseInt(obj.readLine());
Constructor8 obj1=new Constructor8(num1,num2);
Constructor8 obj2=new Constructor8();
obj2.num1=obj1.num1;
obj2.num2=obj1.num2;
obj1.disp();
obj2.disp();
}
}
/*******OUTPUT*******
Enter first number: 25
Enter second number: 25
Addition of these numbers is: 50
Addition of these numbers is: 50
*/