Getters-Setters And This Keyword - Part 3

Complete Step By Step Java for Testers Classes And Methods -> Object Oriented Concepts
3 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€85.55
List Price:  €119.77
You save:  €34.22
£74.16
List Price:  £103.84
You save:  £29.67
CA$137.94
List Price:  CA$193.12
You save:  CA$55.18
A$152.78
List Price:  A$213.90
You save:  A$61.12
S$128.67
List Price:  S$180.14
You save:  S$51.47
HK$780.19
List Price:  HK$1,092.31
You save:  HK$312.11
CHF 80.30
List Price:  CHF 112.42
You save:  CHF 32.12
NOK kr1,004.34
List Price:  NOK kr1,406.11
You save:  NOK kr401.77
DKK kr638.63
List Price:  DKK kr894.11
You save:  DKK kr255.47
NZ$170.14
List Price:  NZ$238.20
You save:  NZ$68.06
د.إ367.21
List Price:  د.إ514.11
You save:  د.إ146.90
৳12,172.20
List Price:  ৳17,041.56
You save:  ৳4,869.36
₹8,825.07
List Price:  ₹12,355.46
You save:  ₹3,530.38
RM422.33
List Price:  RM591.28
You save:  RM168.95
₦152,828.71
List Price:  ₦213,966.31
You save:  ₦61,137.60
₨28,385.35
List Price:  ₨39,740.62
You save:  ₨11,355.27
฿3,218.97
List Price:  ฿4,506.69
You save:  ฿1,287.72
₺4,125.04
List Price:  ₺5,775.22
You save:  ₺1,650.18
B$544.72
List Price:  B$762.63
You save:  B$217.91
R1,768.44
List Price:  R2,475.88
You save:  R707.44
Лв167.48
List Price:  Лв234.49
You save:  Лв67
₩139,005.46
List Price:  ₩194,613.20
You save:  ₩55,607.74
₪333.96
List Price:  ₪467.56
You save:  ₪133.59
₱5,689.88
List Price:  ₱7,966.06
You save:  ₱2,276.18
¥14,815.95
List Price:  ¥20,742.93
You save:  ¥5,926.97
MX$1,867.49
List Price:  MX$2,614.56
You save:  MX$747.07
QR364.04
List Price:  QR509.67
You save:  QR145.63
P1,439.16
List Price:  P2,014.89
You save:  P575.72
KSh12,918.70
List Price:  KSh18,086.70
You save:  KSh5,168
E£4,854.53
List Price:  E£6,796.54
You save:  E£1,942
ብር14,306.63
List Price:  ብር20,029.86
You save:  ብር5,723.22
Kz91,186.39
List Price:  Kz127,664.59
You save:  Kz36,478.20
CLP$97,214.27
List Price:  CLP$136,103.87
You save:  CLP$38,889.60
CN¥713
List Price:  CN¥998.24
You save:  CN¥285.23
RD$6,340.36
List Price:  RD$8,876.76
You save:  RD$2,536.40
DA12,985.04
List Price:  DA18,179.58
You save:  DA5,194.53
FJ$225.61
List Price:  FJ$315.87
You save:  FJ$90.25
Q767.35
List Price:  Q1,074.33
You save:  Q306.97
GY$20,923.93
List Price:  GY$29,294.34
You save:  GY$8,370.41
ISK kr12,250.77
List Price:  ISK kr17,151.57
You save:  ISK kr4,900.80
DH907.55
List Price:  DH1,270.61
You save:  DH363.06
L1,676.34
List Price:  L2,346.95
You save:  L670.60
ден5,281.40
List Price:  ден7,394.17
You save:  ден2,112.77
MOP$803.54
List Price:  MOP$1,124.98
You save:  MOP$321.44
N$1,773.82
List Price:  N$2,483.42
You save:  N$709.60
C$3,680.31
List Price:  C$5,152.59
You save:  C$1,472.27
रु14,096.01
List Price:  रु19,734.98
You save:  रु5,638.96
S/352.21
List Price:  S/493.11
You save:  S/140.90
K423.82
List Price:  K593.36
You save:  K169.54
SAR375.17
List Price:  SAR525.26
You save:  SAR150.08
ZK2,380.02
List Price:  ZK3,332.12
You save:  ZK952.10
L434.52
List Price:  L608.35
You save:  L173.82
Kč2,090.29
List Price:  Kč2,926.49
You save:  Kč836.19
Ft33,616.37
List Price:  Ft47,064.26
You save:  Ft13,447.89
SEK kr940.94
List Price:  SEK kr1,317.36
You save:  SEK kr376.41
ARS$136,236.96
List Price:  ARS$190,737.20
You save:  ARS$54,500.23
Bs691.36
List Price:  Bs967.94
You save:  Bs276.57
COP$399,414.69
List Price:  COP$559,196.55
You save:  COP$159,781.85
₡50,561.46
List Price:  ₡70,788.07
You save:  ₡20,226.60
L2,620.33
List Price:  L3,668.57
You save:  L1,048.24
₲720,925.20
List Price:  ₲1,009,324.12
You save:  ₲288,398.92
$U4,006.62
List Price:  $U5,609.43
You save:  $U1,602.81
zł363.92
List Price:  zł509.51
You save:  zł145.58
Already have an account? Log In

Transcript

Hello all welcome back to the next one. This is gonna be really quick I just wanted to explain you one print statement that was happening in the last lecture. So I made the print statements a little bit more descriptive. This one says make of the BMW s and then BMW get make make of the bench is and Ben's God get make and model of sorry there should be bands these are all bands. So these are all bands. So model of bands bands dot get model ear of Ben's Ben's dot get here.

Now let's run this code. So no changes other than the print statements run as Java application. And currently it's all good because it's 2020 but in the last class we talked about reducing the year and then running it for some validations and then from the methods set here, we are getting this print statement this year is not valid, and we know that it's coming from here this year is non violent. And, and the final line, it's printing error Penza zero, then why is it saying zero from where was the zero coming in the last class, right? We all want to understand that. So what's happening is, this method tried to set the year of 1800 for the bends model, and it went here.

It failed the check, it went to the log, and it just printed out the sphere is not valid. And it never said the value of the air field in this class. So the value is never set. And then in the next statement, we try to access the value we tried to access the value is Ben's dot Guerrier. And when we try to access it, it is returning me the default value of an integer because this is an integer variable. So as returning me that default value of integer which is zero, yes, you guessed it.

Right, which is zero. So let's try to do the same thing with something which we never said. So I'm gonna maybe use the BMW example and maybe the model of BMW s. And we never said it, I have not said it. So BMW dot get model. And model is of type string. So let's just run the code as our application and model of BMW is null.

So null is the default value of string. So when we don't sell anything, and we try to access it, we gonna get the default values of that variable, right? And this is also a great reason for using getters and setters. Now, if we never set the value of variables and we try to access them, we will be getting these kind of things, but It's all up to us. It's our code, we can handle it. If we are having getters and setters, we can actually handle these values and the metal inside it like the way if we don't have anything, we can assign any value.

Like, if I'm setting the year and it fails the condition inside the else block. I can say else the default value is something I mean, it's zero, it's fine. But in case you want to do something, you can assign a default value. So so this is also one more great use of getters and setters. So that's about it. I quickly wanted to go over this issue, because I, I noticed it afterwards.

And then I thought that I think people might be wondering why and from where the zero is coming. So all right. Please let me know if you have any other questions, and I'll see in the next lecture. Thanks a lot for attending this one. Thanks.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.