-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathj39ConstructorAndConstructorOverloading.java
More file actions
43 lines (36 loc) · 1.36 KB
/
j39ConstructorAndConstructorOverloading.java
File metadata and controls
43 lines (36 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
class BankAccount{
// always declare teh variable first
// then use in constructor
String Name;
int id;
private int Salary;
// if we make class same name method inko at a time of incialization of class
public BankAccount (String name , int id_in , int Sal){
// this is Constuructor for this class// we can direct i=recieve value at time of initiaklise
// by passing parameters in
Name = name;
id = id_in;
Salary = Sal;
}
// we can also use metheod Overloading with constructor
public BankAccount(){
// constructor with no argument
Name = "Puppet";
id = 111;
Salary = 0000000;
System.out.println("This Is fake details creted by Computer !");
}
public void PrintDetails(){
System.out.printf("\nYour Name : %s , Id is : %d , Salary : %d \n\n" , Name , id ,Salary);
}
}
public class j39ConstructorAndConstructorOverloading{
public static void main(String[] args){
BankAccount ved = new BankAccount("Ved Prakash Gupta" , 101 , 1000000); // initialize with argus
ved.PrintDetails();
// initialise BankAccount Class withourt Argus
System.out.println("initialise BankAccount Class withourt Argus");
BankAccount aj = new BankAccount();
aj.PrintDetails();
}
}