<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-377664858105659896</id><updated>2024-10-24T22:18:37.324-07:00</updated><title type='text'>The LadyTeacher{ }</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://theladyteacher.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/377664858105659896/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://theladyteacher.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Mary Herberth</name><uri>http://www.blogger.com/profile/02010937060846036961</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>1</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-377664858105659896.post-1621264058315774884</id><published>2011-12-26T04:01:00.000-08:00</published><updated>2013-02-16T07:58:21.224-08:00</updated><title type='text'>Oops! Oop is so easy and fun to learn.</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;Hi, this is Mary Herberth, a private computer-science teacher (for interested high school students) by profession for over a decade now. I&#39;d like to share the way I used to teach a bunch of my students the basics of Java that I found effective, easy and effortlessly graspable. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;This was how it all started with the unorthodox procedure I&#39;d designed:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;Disclaimer: Some of the stuff used to explain a few things might be mischievous. &lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;span style=&quot;font-size: small;&quot;&gt;-------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&amp;nbsp;&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju5VQzYmfXlNuJTav3yqn3PDT3MKUNFccHbs8cgFyuenk2lgE69ywwHc4Z5c_i93gDE-Xwt_aH2IkCLKgXkFSNg-0F8jYgTStuW0g6sAYnVHA7FkQKhdmA3rvnXoDrN8cicbhk8Gy1YTM/s1600/woman-teacher-happy.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;320&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju5VQzYmfXlNuJTav3yqn3PDT3MKUNFccHbs8cgFyuenk2lgE69ywwHc4Z5c_i93gDE-Xwt_aH2IkCLKgXkFSNg-0F8jYgTStuW0g6sAYnVHA7FkQKhdmA3rvnXoDrN8cicbhk8Gy1YTM/s320/woman-teacher-happy.png&quot; width=&quot;256&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;

&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;--------------------------------------------------------------------------------------------------------------------------&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;Well consider me
as a ‘class’ – a LadyTeacher class. That actually means I’m like a template for
creating other ‘LadyTeacher’ objects, much like a blueprint.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;And as a ‘class’,
I can have, basically, my &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;instance variables&lt;/i&gt;&lt;/b&gt; and &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;methods&lt;/i&gt;&lt;/b&gt;.
&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;Instance variables&lt;/b&gt;’ are &lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;what I have&lt;/i&gt;, while ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;methods’&lt;/b&gt; are &lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;what I can do&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;span&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&amp;nbsp;&lt;/span&gt;Roses are red
and violets are blue,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;&lt;span&gt;‘Instance
Variables’&lt;/span&gt;&lt;/i&gt;&lt;/b&gt;&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;span&gt; are ‘&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;what I
have’&lt;/i&gt; and ‘&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;methods&lt;/i&gt;’ are ‘&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;what I can do’&lt;/i&gt;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;To illustrate, my
‘qualification’, ‘experience’ and even my ‘beauty’ (which itself might be an
object of ‘Beauty’ class) are all my ‘instance variables’.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;Meanwhile, some
stuff that I could do, like doTeaching(), clearDoubts(), giveTuitions() are my
methods – because I can ‘do’ them.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;However, I’m not a
standalone authority teaching you here but I adhere to some norms, of say
Teachers’ Association, who mandate all teachers to implement some methods (note
the word ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;mandatory’&lt;/i&gt;&lt;/b&gt;).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;So, I’m said of ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;implementing’&lt;/i&gt;&lt;/b&gt;
an ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;interface’&lt;/i&gt;&lt;/b&gt;
(Teachers’ Association) and I’m compelled to &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;implement&lt;/i&gt;&lt;/b&gt; its &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;methods&lt;/i&gt;&lt;/b&gt;.
(Say it mandates me to take attendance of students)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;Syntactically,&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-left: 0.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;public
class LadyTeacher implements TeachersAssociation {&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 0.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;public
void takeAttendance()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 0.5in; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 0.5in; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;} &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 0.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-left: 0.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;Wait, you might
ask what’s that ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;public’&lt;/i&gt;&lt;/b&gt; for in ‘public void takeAttendance()’ ??&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;Well, imagine I’ve
got a set of methods (&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;what I could ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;do’&lt;/b&gt;&lt;/i&gt;) and each one of them is of a &lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;different kind&lt;/i&gt; for me. For example,
takeAttendance() is a method I’m not much worried about and hence I don’t mind
if it’s called from outside of my class or outside of my package. So I keep it
‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;public’&lt;/b&gt; – “&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;visible from anywhere&lt;/i&gt;&lt;/b&gt;”.
And this applies to methods. When it comes to variables, there are some minor
changes which I’ll explain you soon.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;But imagine I’ve
got a method called &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;checkMyAge()&lt;/i&gt;&lt;/b&gt; that returns my &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;presentAge&lt;/b&gt; (&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;a variable, what
I ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;have’&lt;/b&gt;&lt;/i&gt;). Obviously, I don’t
want an outsider to know my age (although I can fake and return ‘18’ every time
someone calls it). I’m having that method just for my internal calculations,
say to fill up some form and is supposed to be called only from my class. No
one else should be able to use it &lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;upon me&lt;/i&gt;.
So, I declare it ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;private’&lt;/i&gt;&lt;/b&gt;. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;Also, since I’m a &lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;lady&lt;/i&gt; teacher, I, by default, have all
the &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;methods&lt;/i&gt;&lt;/b&gt;
(&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;what I could ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;do’&lt;/b&gt;&lt;/i&gt;) of a ‘&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;Lady’&lt;/i&gt;, as
a Lady teacher can still deliver a baby.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;This eases my task
of taking care of most of my &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;methods&lt;/i&gt;&lt;/b&gt; just by extending ‘Lady’
class, inheriting all its methods at once (This does allow me to have my own
teacher-specific &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;methods&lt;/i&gt;&lt;/b&gt; as well).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-left: 0.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;public
class LadyTeacher extends Lady implements TeachersAssociation{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;public
void takeAttendance()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 0.5in; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 0.5in; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;} &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 0.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-left: 0.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;But wait, I’m not
just a lady, I’m an alumnus of Harvard University too, I need THEIR &lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;methods&lt;/i&gt; as well! Cool, I can inherit
multiple classes??&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;Well, it turns out
that you can’t. Java does NOT allow ‘multiple inheritance’. A class can have at
most, one superclass. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;But implementing
multiple interfaces is allowed, you can use them.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;Why I am not
allowed to extend multiple classes?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;Well, the answer
looks pretty simple. But before we get there, let me tell you what &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;‘overriding
a method’&lt;/i&gt;&lt;/b&gt; is.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;As I told you, a
method is something which I ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;do’&lt;/i&gt;&lt;/b&gt;. Now if I extend a class, say
Lady class, by default I inherit all the &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;public&lt;/i&gt;&lt;/b&gt; and &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;protected&lt;/i&gt;&lt;/b&gt; methods (‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;do’&lt;/i&gt;&lt;/b&gt;)
of the Lady class. This makes my life easier as I need not write method bodies
for washClothes(), wearABra() etc again because they are already present in my
superclass, the Lady class. But imagine, I’m such a pervert that I don’t wish
to wear a bra and hence want to return false (or null) for wearABra() method.
How could I achieve that? There comes this concept of &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;method overriding&lt;/i&gt;&lt;/b&gt;: You
override a method by including it in your class and coding it the way you wish.
So, I override wearABra() in my class.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;margin-left: 0.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;public
class LadyTeacher extends Lady implements TeachersAssociation{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;public
void takeAttendance()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 0.5in; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 0.5in; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;} &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;public
String wearABra()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 0.5in; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;&lt;span style=&quot;mso-spacerun: yes;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/span&gt; &lt;/span&gt;return(“It’s none
of your business”); &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 0.5in; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 0.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-left: 0.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;Coming to the
previous question: Why not am I allowed to extend multiple classes?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;In a line, to
avoid conflicts while calling methods. Elaborating, if I (the Teacher class)
extend two classes, say HarvardUniversity class and KennedyHighSchool class
(this was where I did my schooling) which are both in-turn extended from one
single superclass , say EducationalInstitutions class, then when any method of
this superclass (EducationalInstitutions) if overridden by both its subclasses
(HarvardUniversity and KennedyHighSchool) , say calculateGrade() method, is
called from my class (the Teacher class where that’s not overridden), then
there’s an obvious ambiguity for the JVM in deciding which of them should be
called. Single inheritance avoids this.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;So what’s the
workaround?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;You can implement
multiple interfaces (be careful while interpreting this, YOU CAN IMPLEMENT
MULTIPLE INTERFACES, not the methods again). This gives you a decent way of
using whatever methods you’d like to call.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;Now imagine some
method (&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;what I ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;do’&lt;/b&gt;&lt;/i&gt;) say, getExperienceInfo() which I want to be used by myself
and anyone who’s sitting in my super-class hierarchy. That’s the default
accessor, you don’t need to specify anything for them. There’s a last type of
accessor called ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;protected’&lt;/i&gt;&lt;/b&gt; that can be called by anyone from within your
‘package’ (More on packages in next class).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;But before
anything else, I’d like to tell you how the LadyTeacher objects (&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;the
individual LadyTeacher &lt;/i&gt;&lt;/b&gt;s) are created. Every class has something called
a ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;constructor’&lt;/i&gt;&lt;/b&gt;.
When you create an instance of a class, or speaking of this context, if you
create a LadyTeacher &lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;object&lt;/i&gt; (&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;an individual LadyTeacher&lt;/i&gt;) out of the
LadyTeacher class, it’s the constructor where the ‘creation’ happens.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;This is how you
create a LadyTeacher object using its constructor typically:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;LadyTeacher
missClara = new LadyTeacher(); // here missClara is the name of the LadyTeacher
object you’ve just created. Note that this is the name of the teacher variable,
not of the just created teacher.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;With this, a part
of &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;heap&lt;/i&gt;&lt;/b&gt;
is allotted to the newly created &lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;LadyTeacher&lt;/i&gt;
&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;object&lt;/i&gt;, missClara.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;We call
‘missClara’ a &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;reference&lt;/i&gt;&lt;/b&gt; to the object freshly created. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;Now to do this,
the LadyTeacher class should contain a constructor or any superclass from its
superclass hierarchy should. By default, all classes are primarily extended
from the ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;Object’&lt;/i&gt;&lt;/b&gt; class. So if none of the classes used appear to contain
the constructor, don’t worry, &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;Object&lt;/i&gt;&lt;/b&gt; class provides one, at least
that’s not an error, although most of the time you would be providing or using
some constructor aptly.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;Okay, let’s create
a &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;constructor&lt;/i&gt;&lt;/b&gt;
for our &lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;LadyTeacher&lt;/i&gt;. But wait, while
creating a new object (a new LadyTeacher in this case), one might be having
different criteria or parameters, say sometimes one wouldn’t be knowing the
teacher’s name, sometimes you do and such. To facilitate all that, you can have
multiple constructors in your class, all with the same name – &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;the class name itself&lt;/b&gt;, but with
different parameters. Typically, as just mentioned, the name of the constructor
is the name of the class itself.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;As illustrated
below, here there are two constructors (with the same name- the class name
itself), one of which doesn’t take any argument and the other requires the name
of the teacher. If you call the first constructor while creating a new &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;LadyTeacher&lt;/i&gt;&lt;/b&gt;
(object), it assigns missJenkins as the name of that teacher.(Note here:
nameOfTeacher is an &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;instance variable&lt;/i&gt;&lt;/b&gt; as I mentioned already, &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;something I have&lt;/i&gt;&lt;/b&gt;) . On
the other hand, if you want to name your teacher yourself, you need to call the
second constructor to whom you need to pass the name, like this:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-left: 0.5in; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;LadyTeacher missClara = new LadyTeacher(“Clara
Hatterbern”);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-left: 0.5in; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;And this is the
class now:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-left: 1in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;public
class LadyTeacher extends Lady implements TeachersAssociation{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1in; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;String nameOfTeacher;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;&lt;span style=&quot;mso-tab-count: 1;&quot;&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;public LadyTeacher()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1in; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1.5in; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;nameOfTeacher = missJenkins; &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1in; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1in; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;public
LadyTeacher(String name1)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1.5in; text-align: justify; text-indent: 0.5in;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;nameOfTeacher = name1;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;public
void takeAttendance()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;//......&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;}
&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&lt;span style=&quot;background-color: white;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;public
String wearABra()&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;{&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;return(“It’s
none of your business”);&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1.5in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;span style=&quot;background-color: yellow;&quot;&gt;

&lt;/span&gt;&lt;div style=&quot;margin-left: 1in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;span style=&quot;background-color: yellow;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;margin-left: 1in; text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;This particular
thing what you just saw is called “&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;constructor overLOADING&lt;/i&gt;&lt;/b&gt;&quot;. In
general, any method can be overloaded this way keeping in mind that their &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;signature&lt;/i&gt;&lt;/b&gt;(the
&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;argument
list&lt;/i&gt;&lt;/b&gt; and the &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;return value&lt;/i&gt;&lt;/b&gt; are collectively
referred as the &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;signature&lt;/i&gt;&lt;/b&gt; of a method) should be different. In that case, it’s
referred as ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;method overLOADING&lt;/i&gt;&lt;/b&gt;’.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;Now imagine you
need to know how many LadyTeachers are there in the whole of US of A.
Obviously, to be a &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;LadyTeacher&lt;/i&gt;&lt;/b&gt;, one has to create the &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;LadyTeacher&lt;/i&gt;&lt;/b&gt; instance. So,
understandably, the total number of &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;LadyTeacher&lt;/i&gt;&lt;/b&gt; &lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;objects&lt;/i&gt; created is what we are looking for. But how do we calculate
this? Yes, we need to keep a counter. Where? Right, inside the &lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;constructor&lt;/i&gt; of the &lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;LadyTeacher&lt;/i&gt; class, because that’s where LadyTeachers are created.
But it should be done in such a way that it’s the property of the &lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;class&lt;/i&gt; and not of the individual objects
(individual LadyTeachers). Obviously, why should any specific LadyTeacher be
keeping the count of the total number of LadyTeachers of the country? There
come the ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;static’&lt;/b&gt; variables. As told
before, ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;variables’&lt;/i&gt;&lt;/b&gt; are those which we ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;have’&lt;/i&gt;&lt;/b&gt;. ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;static’&lt;/i&gt;&lt;/b&gt;
variables are those which are &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;specific to a class&lt;/i&gt;&lt;/b&gt; (&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;LadyTeacher&lt;/i&gt; class) rather than to the
individual objects (individual LadyTeacher s). Other way put, ‘&lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;static
variables&lt;/i&gt;&lt;/b&gt;’ are &lt;b style=&quot;mso-bidi-font-weight: normal;&quot;&gt;NOT&lt;/b&gt; the
property of any object (any LadyTeacher herself) but of the &lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;class&lt;/i&gt; (the LadyTeacher class, the
blueprint). So ‘&lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;static variables&lt;/i&gt;’
retain their values throughout and it &lt;i style=&quot;mso-bidi-font-style: normal;&quot;&gt;doesn’t
get re-initialized when new objects are created&lt;/i&gt; (well, unless that’s not
what are looking for).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;===== to be
continued in the next class =====&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;margin: 0in 0in 0pt;&quot;&gt;
&lt;span style=&quot;font-size: 10pt;&quot;&gt;&lt;o:p&gt;&lt;span style=&quot;font-size: small;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://theladyteacher.blogspot.com/feeds/1621264058315774884/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://theladyteacher.blogspot.com/2011/12/oops-oop-is-so-easy-and-fun-to-learn.html#comment-form' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/377664858105659896/posts/default/1621264058315774884'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/377664858105659896/posts/default/1621264058315774884'/><link rel='alternate' type='text/html' href='http://theladyteacher.blogspot.com/2011/12/oops-oop-is-so-easy-and-fun-to-learn.html' title='Oops! Oop is so easy and fun to learn.'/><author><name>Mary Herberth</name><uri>http://www.blogger.com/profile/02010937060846036961</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEju5VQzYmfXlNuJTav3yqn3PDT3MKUNFccHbs8cgFyuenk2lgE69ywwHc4Z5c_i93gDE-Xwt_aH2IkCLKgXkFSNg-0F8jYgTStuW0g6sAYnVHA7FkQKhdmA3rvnXoDrN8cicbhk8Gy1YTM/s72-c/woman-teacher-happy.png" height="72" width="72"/><thr:total>10</thr:total></entry></feed>