0:00:00.060,0:00:03.129 [Music] 0:00:03.520,0:00:07.040 in this exercise we're given these lines 0:00:05.440,0:00:09.440 of code and we're told that it runs an 0:00:07.040,0:00:11.120 error now since we don't actually know 0:00:09.440,0:00:11.920 what the class looks like let's guess 0:00:11.120,0:00:14.080 together 0:00:11.920,0:00:15.280 so let's say it's probably person class 0:00:14.080,0:00:16.480 right that makes sense because that's 0:00:15.280,0:00:18.240 what's being called 0:00:16.480,0:00:20.480 and there might be other code but we 0:00:18.240,0:00:25.519 know that there is a private hi 0:00:20.480,0:00:26.960 method let's say it just outputs hi 0:00:25.519,0:00:31.840 and let's see if this is giving us the 0:00:26.960,0:00:31.840 same error 0:00:32.000,0:00:35.440 and it does okay so private method hi 0:00:34.320,0:00:39.280 called for person 0:00:35.440,0:00:41.360 so we have recreated the error 0:00:39.280,0:00:42.640 so how can we fix this well really the 0:00:41.360,0:00:44.320 easiest way to fix it is just 0:00:42.640,0:00:46.000 take away the word private and now it's 0:00:44.320,0:00:47.760 a public method 0:00:46.000,0:00:49.680 so now when we try to run this it 0:00:47.760,0:00:51.520 outputs high and it works fine 0:00:49.680,0:00:53.199 but maybe there's a reason that this 0:00:51.520,0:00:54.960 method is private maybe 0:00:53.199,0:00:56.239 for some reason it exposes sensitive 0:00:54.960,0:00:58.879 information obviously 0:00:56.239,0:01:01.359 it currently doesn't but let's just play 0:00:58.879,0:01:02.879 along for instructional purposes 0:01:01.359,0:01:05.760 now another way we could do this is 0:01:02.879,0:01:08.000 create another method called public high 0:01:05.760,0:01:10.840 and this could call the private method 0:01:08.000,0:01:13.840 high so we can call it 0:01:10.840,0:01:16.960 hi oh it still doesn't work 0:01:13.840,0:01:19.360 and so now we go down here and use 0:01:16.960,0:01:22.400 public high and now we call this 0:01:19.360,0:01:23.040 and now it works great so that's one way 0:01:22.400,0:01:24.720 to do it 0:01:23.040,0:01:25.759 now this is kind of a contrived example 0:01:24.720,0:01:27.040 so it kind of looks like why in the 0:01:25.759,0:01:28.560 world would we do this 0:01:27.040,0:01:30.640 but let's say there was some sensitive 0:01:28.560,0:01:32.560 information here and in the public high 0:01:30.640,0:01:33.759 method we maybe needed to use that 0:01:32.560,0:01:34.720 method but there was some kind of 0:01:33.759,0:01:37.520 validation 0:01:34.720,0:01:38.880 or we changed the output or made it look 0:01:37.520,0:01:40.799 a little bit different 0:01:38.880,0:01:42.960 so that we need the functionality of 0:01:40.799,0:01:44.720 high but we somehow did something in 0:01:42.960,0:01:45.840 this public high method that made it 0:01:44.720,0:01:48.159 acceptable 0:01:45.840,0:01:50.479 the basic idea here though is you can 0:01:48.159,0:01:51.360 call private methods inside the class 0:01:50.479,0:01:53.520 like this 0:01:51.360,0:02:02.000 or you can simply take away private and 0:01:53.520,0:02:02.000 make it a public method