forked from maheshashokit/27_Java_Full_Stack_Repo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMobile.java
More file actions
84 lines (67 loc) · 2.84 KB
/
Mobile.java
File metadata and controls
84 lines (67 loc) · 2.84 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
public class Mobile {
//Declaring the Fields
private String modelNo;
private double price;
private String companyName;
//Defining the Constructor
public Mobile() {
System.out.println("Mobile Class Non-Parameterized Constructor.......");
}
//Defining the Parameterized Constructor
public Mobile(String mobileModel,double mobilePrice,String compName) {
System.out.println("Mobile Class Three Parameterized Constructor......");
modelNo = mobileModel;
price = mobilePrice;
companyName = compName;
}
//It will call Non-Parameterized Constructor and we are not sending any data
public Mobile(String mobileModel,String compName,double mobilePrice) {
System.out.println("Mobile Class Three Parameterized Constructor Changed in Order......");
modelNo = mobileModel;
price = mobilePrice;
companyName = compName;
}
//Defining the another Parameterized Constructor
public Mobile(String mobileModel,String compName) {
System.out.println("Mobile Class Two Parameterized Constructor......");
modelNo = mobileModel;
companyName = compName;
}
//Defining the another Parameterized constructor which accepts Mobile as Parameter
public Mobile(Mobile mob) {
System.out.println("Mobile Class Copy Constructor.....");
modelNo = mob.modelNo;
price=mob.price;
companyName=mob.companyName;
}
//Defining the method for displaying values
public void displayMobileInfo() {
System.out.println("Mobile Model No :::::::" + modelNo);
System.out.println("Mobile Price :::::::" + price);
System.out.println("Company Name :::::::" + companyName);
}
public static void main(String[] args) {
//Creating Mobile Object with out passing any data
//It will call Non-Parameterized Constructor and we are not sending any data
Mobile mob = new Mobile();
//calling the displayMobileInfo();
mob.displayMobileInfo();
System.out.println("****************************************");
//It will call Parameterized constructor to Intialiaze the values
Mobile mob1 = new Mobile("RealMeU1",25000.00d,"RealME");
//calling the displayMobileInfo() using mob1 object
mob1.displayMobileInfo();
System.out.println("******************************************");
//It will call two Parameterized constructor to Initialize the values
Mobile mob2 = new Mobile("SAMSUNGM31","Samsung");
//calling the displayMobileInfo() using mob2 object
mob2.displayMobileInfo();
System.out.println("**********************************************");
Mobile mob3 = new Mobile("IPHONE7","APPLE",60000.00d);
//calling the displayMobileInfo()
mob3.displayMobileInfo();
System.out.println("************************************************");
Mobile mob4 = new Mobile(mob3); //mob3 is an existing object where mob4 is newly created object
mob4.displayMobileInfo();
}
}