-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConstructorExample.java
51 lines (38 loc) · 1.4 KB
/
ConstructorExample.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
package com.javaexperiments;
public class ConstructorExample {
private String accountNumber;
private String accountName;
private double balance;
public ConstructorExample(String accountNumber, String accountName, double balance) {
this.accountNumber = accountNumber;
this.accountName = accountName;
this.balance = balance;
}
public String getAccountNumber() {
return accountNumber;
}
public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void deposit(double depositAmount) {
balance += depositAmount;
System.out.println("The amount deposited is " + depositAmount + " and balance is " + balance);
}
public static void main(String[] args) {
ConstructorExample constructorExample = new ConstructorExample("123456", "Vivek", 2000.0);
System.out.println("The account belongs to " + constructorExample.accountName + " with account number: "
+ constructorExample.accountNumber + " and balance: " +constructorExample.balance);
}
}