<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Yuehui Ruan</title>
    <description>The latest articles on DEV Community by Yuehui Ruan (@divide_r_conquer).</description>
    <link>https://dev.to/divide_r_conquer</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F690094%2Ff8e37e46-9478-438a-ad91-5f6fcc52af50.png</url>
      <title>DEV Community: Yuehui Ruan</title>
      <link>https://dev.to/divide_r_conquer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/divide_r_conquer"/>
    <language>en</language>
    <item>
      <title>Three characteristics of OOP: Polymorphism</title>
      <dc:creator>Yuehui Ruan</dc:creator>
      <pubDate>Fri, 28 Jan 2022 02:31:03 +0000</pubDate>
      <link>https://dev.to/divide_r_conquer/three-characteristics-of-oop-polymorphism-1lna</link>
      <guid>https://dev.to/divide_r_conquer/three-characteristics-of-oop-polymorphism-1lna</guid>
      <description>&lt;h3&gt;
  
  
  Polymorphism:
&lt;/h3&gt;

&lt;p&gt;Finally, I begin to write about POLYMORPHISM section. This section needs me get much more familier with the core knowledge of &lt;em&gt;Three Main Features Of Java&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Inheritance maybe not the most popular in code, but the most important part of programming (at least, I think so XD).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. What is Polymorphism:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Polymorphism is the implementation of an object having different manifestations.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For example, pressing the same button "ENTER" in different applications, computer will show up different reactions, like acting &lt;br&gt;
 "Line Feed" function in Word application, acting "Send" function after you type the text in chat box, etc. Just like invoking the same function, pressing "ENTER" button plays an different roles in different applications. This is also kind of Polymorphism.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Significance of Polymorphism :&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Remove coupling between classes&lt;/li&gt;
&lt;li&gt;Replaceability&lt;/li&gt;
&lt;li&gt;Scalability&lt;/li&gt;
&lt;li&gt;Working as interface (like a real &lt;code&gt;interface&lt;/code&gt; in Java)&lt;/li&gt;
&lt;li&gt;Flexibility&lt;/li&gt;
&lt;li&gt;Simplicity&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Before describing all of its significance, there are three necessary conditions for the existence of polymorphisms that you should know:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The implementance of inheritance: So you can see, the implementance of polymorphsm is also the implementance of &lt;/li&gt;
&lt;li&gt;Override&lt;/li&gt;
&lt;li&gt;An reference of father class points to an object of a sub class: &lt;code&gt;Parent p = new Child();&lt;/code&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now we have classes in our program:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6env33zyq3ir8dfw7p1q.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6env33zyq3ir8dfw7p1q.jpg" alt="2384ed46c6540cea9eb1415086bf8c89_2DAC601E-70D8-4B3C-86CC-7E4972FC2466"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And we have codes for these:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Shape&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{}&lt;/span&gt;&lt;span class="c1"&gt;// is overridden&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Circle&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Shape&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="c1"&gt;//override function draw() of class Shape&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Circle.draw()"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Square&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Shape&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="c1"&gt;//override function draw() of class Shape&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Square.draw()"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Triangle&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Shape&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;draw&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="c1"&gt;//override function draw() of class Shape&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Triangle.draw()"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a method is called in polymorphic mode, it is first checked to see if the method exists in the parent class. If it does not, a compile error occurs. If so, call the method of the same name in the subclass. The phenomenon of calling a function in a subclass with the same name as the one of father class, but showing different results is called Override.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkrn1ru5f51j9apo77z74.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkrn1ru5f51j9apo77z74.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The best way to demonstrate these 6 advantages is to look at the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;abstract&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="c1"&gt;// Abstraction&lt;/span&gt;
    &lt;span class="kd"&gt;abstract&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;eat&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;eat&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="c1"&gt;// Interface&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Eat fish."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;work&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Catch mouse."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;eat&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Eat bone."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;work&lt;/span&gt;&lt;span class="o"&gt;()&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Guard."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Test&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;show&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;  &lt;span class="c1"&gt;// Invoke the show() through the object of class Cat&lt;/span&gt;
        &lt;span class="n"&gt;show&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="o"&gt;());&lt;/span&gt;  &lt;span class="c1"&gt;// Invoke the show() through the object of class Cat&lt;/span&gt;

        &lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;  &lt;span class="c1"&gt;// Upcasting&lt;/span&gt;
        &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;eat&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;               &lt;span class="c1"&gt;// Invoke eat() of class Cat&lt;/span&gt;
        &lt;span class="nc"&gt;Cat&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Cat&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;        &lt;span class="c1"&gt;// Downcasting&lt;/span&gt;
        &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;work&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;        &lt;span class="c1"&gt;// Invoke work() of class Cat&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;show&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Animal&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;  &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;eat&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="c1"&gt;// Judging the class type&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Cat&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;  &lt;span class="o"&gt;{&lt;/span&gt;  &lt;span class="c1"&gt;// What a cat does&lt;/span&gt;
            &lt;span class="nc"&gt;Cat&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Cat&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;work&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="k"&gt;instanceof&lt;/span&gt; &lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// What a dog does&lt;/span&gt;
            &lt;span class="nc"&gt;Dog&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Dog&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
            &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;work&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And you can see the output:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Eat fish.&lt;br&gt;
Catch mouse.&lt;br&gt;
Eat bone.&lt;br&gt;
Guard.&lt;br&gt;
Eat fish.&lt;br&gt;
Catch mouse.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;3. How to implement Polymorphism:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1. Override: &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Override exists for polymorphisms.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;We've already discussed method overrides, which are methods that can be overridden by a sub class.&lt;/p&gt;

&lt;p&gt;When a subclass object calls an overridden method, the method in the subclass is called, not the overridden method in the superclass.&lt;/p&gt;

&lt;p&gt;To call an overridden method in a parent class, you must use the &lt;code&gt;super&lt;/code&gt; keyword.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;2. Interface&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Interfaces in Java are similar to interfaces in life, which are collections of method characteristics, but no method implementation. See the &lt;a href="https://www.tutorialspoint.com/java/java_interfaces.htm" rel="noopener noreferrer"&gt;Java Interfaces&lt;/a&gt; section for details.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;3. Abstract classes and abstract functions (vitural function)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Virtual functions also exist for polymorphisms.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Of course, the implementation of polymorphism is not only about the interation among classes. It also can be implemented by &lt;code&gt;abstract function()&lt;/code&gt; and &lt;code&gt;abstract class {}&lt;/code&gt;(like the vitural func() in c++). &lt;/p&gt;




&lt;h3&gt;
  
  
  Last but not least
&lt;/h3&gt;

&lt;p&gt;Those concepts of &lt;code&gt;abstract&lt;/code&gt; and &lt;code&gt;override&lt;/code&gt; could be written in another blogs. However, this blog is the first blog of mine, I hope I could get some feedbacks and advice from our members of DEV community, and then move forward again.&lt;/p&gt;

&lt;p&gt;Your advice and comments are the power of my moving forward. Thank you for your reading.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Never know how good you will be if you don't push yourself.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Ricky Ruan:&lt;/p&gt;

&lt;p&gt;E-mail: &lt;a href="mailto:yruan@umass.edu"&gt;yruan@umass.edu&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>computerscience</category>
      <category>beginners</category>
      <category>internship</category>
    </item>
    <item>
      <title>Three characteristics of OOP: Inheritance</title>
      <dc:creator>Yuehui Ruan</dc:creator>
      <pubDate>Fri, 28 Jan 2022 02:28:30 +0000</pubDate>
      <link>https://dev.to/divide_r_conquer/three-characteristics-of-oop-inheritance-377d</link>
      <guid>https://dev.to/divide_r_conquer/three-characteristics-of-oop-inheritance-377d</guid>
      <description>&lt;h3&gt;
  
  
  Inheritance : W W H
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Defination (What):&lt;/strong&gt;&lt;br&gt;
Key word: &lt;code&gt;extend&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When multiple classes have common attributes (member variables) and behavior (member methods), these common parts are extracted and defined in a public class. Other classes and classes can form an inheritance relationship with this public class, so that there is no need to redefine the public part in multiple classes! This common class is the parent class, also known as the superclass or base class, and the other classes are the subclasses. Subclasses can access non-private member variables of the parent class directly, and private member variables of the parent class can be accessed using the super.get() method.&lt;/p&gt;

&lt;p&gt;Now we have the codes at the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Toyota"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;books&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Harry Potter"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// son extends from his father&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Test&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Father&lt;/span&gt; &lt;span class="n"&gt;Howard_Stark&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="n"&gt;Tony_Stack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Tony_Stack&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;car&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Seems like son has nothing. However, once the son extends from his father, Tony now could drive the car from his father and read the books, which his father "confer" to him.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Test&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Father&lt;/span&gt; &lt;span class="n"&gt;Howard_Stark&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="n"&gt;Tony_Stack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Tony_Stack&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;car&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// output: Toyota&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Tony_Stack&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;books&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;// output: Harry Potter&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Some features that you should pay attention about the Inheritance in Java:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Every sub class is prowerful than base class, which means sub class would have or cover more vars and funcs than father class has. (Of course, Iron man Tony is much more greater than his father Howard haha)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Even son extends from his father, son could not "change" the feature of his father. The reason why son could not change his father's feature is that, father and son are two independent instances of &lt;code&gt;class Son&lt;/code&gt; and &lt;code&gt;class Father&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Test&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Father&lt;/span&gt; &lt;span class="n"&gt;Howard_Stark&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="n"&gt;Tony_Stack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;

        &lt;span class="n"&gt;Tony_Stack&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Mercedes"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="c1"&gt;//Tony changes his car to Mercedes, but could not change Howard's car.&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Howard_Stark&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;car&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// output: Toyota&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Tony_Stack&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;car&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// output: Mercedes&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hence, what Tony has in the future does not Howard's business, including his Mark One and Mark Two. That's why son class is absolutely greater than father class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Toyota"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;books&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Harry Potter"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// son extends from his father&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;suit1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Mark One"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;suit2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Mark Two"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Java is single inheritance, not multiple inheritance (unlike C++). However, it is possible to build multi-level subclasses of inheritance.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Like Tony extends from Howard, Morgan Stark (Tony's daughter) extends from Tony, but Morgan could not extend from Howard and Tony at the same time.&lt;/p&gt;

&lt;p&gt;Tony_Stark &amp;lt;-(extends)-- Howard_Stark&lt;br&gt;
Morgan_Stark &amp;lt;-(extends)-- Tony_Stark&lt;/p&gt;

&lt;p&gt;Morgan_Stark &amp;lt;--X-- Howard_Stark, Tony_Stark &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Significance(Why):&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;If a class want to get a same function from another class, it can set up an inheritance. (Save your time to coding, and increase the reusing rate of code)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;2.Encapsulation and inheritance are the prerequisites for polymorphism implementation.&lt;/p&gt;

&lt;p&gt;Of course, when you edit the feature of father class, the common features that the son has would be changed too, unless the son change these common features independently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Implementation(How):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It is the best time to implement inheritance among classes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When those classes have many properties in common.&lt;/li&gt;
&lt;li&gt;When there are obviously relationship among those classes (like &lt;code&gt;class animals&lt;/code&gt; includes &lt;code&gt;class dog&lt;/code&gt; and &lt;code&gt;class cat&lt;/code&gt;, so &lt;code&gt;class cat&lt;/code&gt; and &lt;code&gt;class dog&lt;/code&gt; extends the proteries from &lt;code&gt;class animals&lt;/code&gt;).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After knowing when to use inheritance, you can try to build up the relationship and have a rough frame in your mind.&lt;/p&gt;

&lt;p&gt;I'm going to talk about the six points of inheritance.&lt;/p&gt;

&lt;p&gt;1.When construct an instance of sub class, the complier will invoke the constructor of base class first, and then invoke the constuctor of sub class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Toyota"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;books&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Harry Potter"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Father's constructor invoked"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// son extends from his father&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;suit1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Mark One"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;suit2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Mark Two"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="nc"&gt;Son&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Son's constructor invoked"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Test&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="n"&gt;Tony_Stack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Father's constructor invoked&lt;br&gt;
Son's constructor invoked&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;2.&lt;code&gt;class Object&lt;/code&gt; is the father class of any class in JAVA.&lt;/p&gt;

&lt;p&gt;Hence, every instance (object) in Java is the polymorphism of instance of &lt;code&gt;class Object&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;3.The constructor of a subclass runs super () first, regardless of whether it has arguments or how many;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;super();&lt;/code&gt; equals to default constructor of father class. So you can either explicitly or implicitly call &lt;code&gt;super()&lt;/code&gt; in the any constructor of sub class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Toyota"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;books&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Harry Potter"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// where the super() is.&lt;/span&gt;
    &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Father's constructor invoked"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// son extends from his father&lt;/span&gt;
    &lt;span class="nc"&gt;Son&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="c1"&gt;//super(); default&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Son's constructor invoked"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nc"&gt;Son&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="c1"&gt;//super(); default&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;books&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;book&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.Properties that are private to the parent class are not directly accessible to the subclass in test.java, even if the subclass inherits them. &lt;/p&gt;

&lt;p&gt;You can specify the subclass's parameter-constructor only by calling the parent's parameter-constructor. For properties that are not private to the parent class, the child class object can invoke directly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Toyota"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;books&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Harry Potter"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;bank_account&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"123456"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; 
    &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Father's constructor invoked"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;car&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;car&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nc"&gt;Father&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// son extends from his father&lt;/span&gt;

    &lt;span class="nc"&gt;Son&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="c1"&gt;//super(); default&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Son's constructor invoked"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Test&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Son&lt;/span&gt; &lt;span class="n"&gt;Tony_Stack&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Son&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;Tony_Stack&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;bank_account&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"111111"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;&lt;span class="c1"&gt;// error reported: 'bank_account' has private access in 'test.Father'!!!&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Due to the limitation of the paragraph, here are all my knowledge of Inheritance and, there will be more features' details in Polymorphism Section.&lt;/p&gt;




&lt;p&gt;Your advice and comments are the power of my moving forward. Thank you for your reading.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Never know how good you will be if you don't push yourself.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Ricky Ruan:&lt;/p&gt;

&lt;p&gt;E-mail: &lt;a href="mailto:yruan@umass.edu"&gt;yruan@umass.edu&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>computerscience</category>
      <category>beginners</category>
      <category>internship</category>
    </item>
    <item>
      <title>Computer System Cp2.2 Truncating and expanding in C</title>
      <dc:creator>Yuehui Ruan</dc:creator>
      <pubDate>Fri, 28 Jan 2022 02:15:23 +0000</pubDate>
      <link>https://dev.to/divide_r_conquer/csp-cp22-truncating-and-expanding-in-c-3ooe</link>
      <guid>https://dev.to/divide_r_conquer/csp-cp22-truncating-and-expanding-in-c-3ooe</guid>
      <description>&lt;p&gt;If there is a question asking you, what these binary number means in C? (Basing on 32-bit machine, and we defaultly regrad that we are using 32-bit machine, except for spcially mention we are using others)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;1011?&lt;/li&gt;
&lt;li&gt;0100 0001?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Actually, it's hard to be determined, due to the fact that I haven't told you what data type you are using to contain them in this 32-bit machine. &lt;/p&gt;

&lt;p&gt;That is, what binary number 1011 actually is, is basing on the data type that you want to assign.&lt;br&gt;
In different data type, for example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;unsigned integer: 11&lt;/li&gt;
&lt;li&gt;signed integer: -5
(the difference of the range of signed and unsigned are described in &lt;a href="https://dev.to/devide_r_conquer/computer-systems-principles-cp2-nfo"&gt;chapter 2.1&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And, we have 0100 0001:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;unsigned integer: 65&lt;/li&gt;
&lt;li&gt;char: &lt;code&gt;'A'&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That is, the data type you declare in C program, will be determined to how this 32-bit machine "read". &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you declare &lt;code&gt;unsigned int a = 65;&lt;/code&gt;
a is printed as integer &lt;code&gt;65&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;If you declare &lt;code&gt;int *p = 65;&lt;/code&gt;
p is actually an address number 65, pointing a memory place containing an &lt;code&gt;int&lt;/code&gt; variable.&lt;/li&gt;
&lt;li&gt;If you declare &lt;code&gt;unsigned int c = 'A';&lt;/code&gt;
c is actually 65, because when a char type variable is assigned to an &lt;code&gt;int&lt;/code&gt; type, the machine will "read" this memory as an integer, where the ascii code of A is 65.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  But, how it works?
&lt;/h3&gt;

&lt;p&gt;I mean, we already know from chapter 2.1 that, &lt;code&gt;char&lt;/code&gt; using 1 byte (that is 8 bits) to store the value, and &lt;code&gt;unsigned int&lt;/code&gt; use 4 bytes (that is 32 bits) to store the value.&lt;/p&gt;

&lt;p&gt;So now, we are going to thinking questions about &lt;strong&gt;&lt;u&gt;value casting&lt;u&gt;&lt;/u&gt;&lt;/u&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;u&gt;bits truncating (extanding)&lt;/u&gt;&lt;/strong&gt; between different data type in C.&lt;/p&gt;

&lt;p&gt;There are two kinds of casting, obviously having upcasting and downcasting. However, when having casting problem, there are also be with &lt;strong&gt;Extanding&lt;/strong&gt; and &lt;strong&gt;Truncating&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Upcasting: Low byte(s) cast to high bytes.&lt;/li&gt;
&lt;li&gt;Downcasting: High bytes cast to low byte(s).&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There is also casting value between same byte:&lt;br&gt;
signed int =&amp;gt; unsigned int&lt;br&gt;
   or&lt;br&gt;
unsigned int =&amp;gt; signed int&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;h3&gt;
  
  
  Extanding:
&lt;/h3&gt;

&lt;p&gt;Happens in low bytes to high bytes. When a low-byte variable is cast to high-byte variable, the new high bits of high-byte variable will be extanded by&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;&lt;p&gt;0: if the original value is positive&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;1: if the original value is nagetive&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// In memory, c is 0100 0001, which is 1 byte (8 bits).
unsigned char c = 65;

unsigned int a = c; // Upcasting and extanding

//Now in memory, due to c is originally positive 
//number, variable a will be extanding by 0 on new high bit, 
//that is, adding 0s on the left(significant 
//position) till filling all 4 bytes (32 bits)
//a in memory:
//0000 0000 0000 0000 0000 0000 0100 0001

printf("%d", a);
//65
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example 2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;signed char c = -1;
signed int a = c;
printf("%d", a);
//-1
//Explaination:
//c in memory stored as:
//1111 1111
//(The way to figure out how to get the nagetive value from decimal, 
//please read the last chapter, section about 2's complement)
//Then, upcasting the 1111 1111, adding 1 (because original value 
//is nagetive value) on high bit position, so we have this in 4 bytes:
//1111 1111 1111 1111 1111 1111 1111 1111
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Answer by calculator:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--d2SpAty9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h6s4wfq90nryz3ux1q7p.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--d2SpAty9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h6s4wfq90nryz3ux1q7p.jpg" alt="Image description" width="574" height="301"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Truncating:
&lt;/h3&gt;

&lt;p&gt;How about when a high-bit variable casted to a low-bit variable? Obviously, the low-bit variable can not contain that many bits. So it must do the truncating on high bit position.&lt;/p&gt;

&lt;p&gt;Example 3:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;unsigned int a = 129;
//which is 0000 0000 0000 0000 0000 0000 1000 0001
//stored in memory, in 32-bit machine
//now I want to downcast it to signed char
signed char c = a;
printf("%d", c);
//what is the answer?
//It's -127
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Explaination: &lt;br&gt;
&lt;strong&gt;Always remember one sentence:&lt;/strong&gt;&lt;br&gt;
&lt;u&gt;The data type decide the way that the computer reads!&lt;/u&gt;&lt;br&gt;
No matter how this value being stored in memory, the real value that computer will use just depends on how it reads this value.&lt;/p&gt;

&lt;p&gt;Even though 129 is stored as an unsigned integer like:&lt;br&gt;
 0000 0000 0000 0000 0000 0000 1000 0001&lt;br&gt;
But eventually the computer reads this value as a data of signed char, that is, making this value being read only 8 bits from the lowest bit position, which is only&lt;br&gt;
&lt;del&gt;0000 0000 0000 0000 0000 0000&lt;/del&gt; &lt;strong&gt;1000 0001&lt;/strong&gt;&lt;br&gt;
And, 1000 0001 in signed char is -127.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zuCDwjWt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2oxquogjc1da7kd509zq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zuCDwjWt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2oxquogjc1da7kd509zq.png" alt="Image description" width="595" height="300"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Casting between *&lt;em&gt;signed *&lt;/em&gt; and *&lt;em&gt;unsigned *&lt;/em&gt;:
&lt;/h3&gt;

&lt;p&gt;If you follow these rules, you can hardly get lost:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;It's only about how computer reads!&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;Remember, the most significant position of signed value is describing if it is positive(0) or nagetive(1).&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Besides, bit operaters like |, &amp;amp;, &amp;lt;&amp;lt;, &amp;gt;&amp;gt;, &amp;lt;&amp;lt;&amp;lt; should be familiar with, even they are seldom used in our program. But, it did be used so many in like registers, memory allocation and ALU, which are located in the deeper level of system.&lt;/p&gt;

&lt;p&gt;If you have any questions, feel free to comment here!&lt;/p&gt;

</description>
      <category>computerscience</category>
      <category>c</category>
      <category>system</category>
      <category>cpp</category>
    </item>
    <item>
      <title>Computer System - Cp.2 - 1 Bit and Byte in C</title>
      <dc:creator>Yuehui Ruan</dc:creator>
      <pubDate>Thu, 27 Jan 2022 00:25:21 +0000</pubDate>
      <link>https://dev.to/divide_r_conquer/computer-systems-principles-cp2-nfo</link>
      <guid>https://dev.to/divide_r_conquer/computer-systems-principles-cp2-nfo</guid>
      <description>&lt;p&gt;We will go over data repersentation of computer systems this chapter. That is, when we need to think in a computer way, you should know how computer think at first (in binary).&lt;/p&gt;

&lt;h2&gt;
  
  
  Chapter. 2 Repersentation in C
&lt;/h2&gt;




&lt;h3&gt;
  
  
  1. Base
&lt;/h3&gt;

&lt;p&gt;What is the base of a number?&lt;br&gt;
Generally, the number that we use in daily life like 50 dollars, 100 pounds, 1,000,000 people are all base 10, which means that these number are all decimal.&lt;/p&gt;

&lt;p&gt;And usually, there are different bases we use in studying system, like binary number (base 2), octal number (base 8), and hexadecimal number (base 16). &lt;/p&gt;

&lt;p&gt;We can see them being used in computer world:&lt;br&gt;
When the numebr is followed by a character "b", that means it is a binary number:&lt;br&gt;
0101b (BIN) = 0 * 2^3 + 1 * 2^2 + 0 * 2^1 + 1 * 2^0 = 5 (DEX)&lt;/p&gt;

&lt;p&gt;Number like '0X1E', is HEX number:&lt;br&gt;
0X is the prefix of the hexadecimal number. We have: &lt;br&gt;
0X1E (HEX) = 1 * 16^1 + 14 * 16^0 = 30 (DEX) &lt;/p&gt;

&lt;h3&gt;
  
  
  2. Bit and Byte
&lt;/h3&gt;

&lt;p&gt;1 Byte = 8 Bits&lt;br&gt;
And the important repersentations of every data type in C:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--02GuBKSl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/de8ts8vuvqlfulbghou3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--02GuBKSl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/de8ts8vuvqlfulbghou3.png" alt="Image description" width="712" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Specially, one another data type in C is called POINTER, which is also significant:&lt;/p&gt;

&lt;p&gt;Pointer:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;4 bytes in 32-bit-system&lt;/li&gt;
&lt;li&gt;8 bytes in 64-bit-system
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  The knowledge that we are reviewing, is usually based on &lt;u&gt;32-bit systems&lt;/u&gt;
&lt;/h3&gt;

&lt;h3&gt;
  
  
  3. Conversion between different bases
&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- DEC to BIN:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cSUXs2wd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.electrical4u.com/wp-content/uploads/What-are-Decimal-and-Binary-Conversion.png%3Fezimgfmt%3Dng%253Awebp%252Fngcb37%252Frs%253Adevice%252Frscb37-1" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cSUXs2wd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.electrical4u.com/wp-content/uploads/What-are-Decimal-and-Binary-Conversion.png%3Fezimgfmt%3Dng%253Awebp%252Fngcb37%252Frs%253Adevice%252Frscb37-1" alt="Image description" width="700" height="375"&gt;&lt;/a&gt;&lt;br&gt;
 There is the same way to do with other bases number except for BIN.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;BIN to DEC: mentioned above&lt;/li&gt;
&lt;li&gt;X base number to Y base number: 

&lt;ol&gt;
&lt;li&gt;X base to DEC&lt;/li&gt;
&lt;li&gt;And then DEC to Y base&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  4. Addition and multiplication of binary
&lt;/h3&gt;

&lt;h3&gt;
  
  
  5. One's Complement
&lt;/h3&gt;

&lt;p&gt;When comes to 1100 1001 (which is equal to 201 in decimal):&lt;br&gt;
THe 1's complement of 1100 1001 is 0011 0110, which turning 1 to 0, and turning 0 to 1.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. Two's Complement
&lt;/h3&gt;

&lt;p&gt;Two's complement is used to do the substraction or repersenting negative number in binary (Of course, adding a negative is substracting a positive number).&lt;br&gt;
How to repersent -5 in binary, when we know 5 is 0101 in binary in a 8-bit machine?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Get the 0101's 1's complement in 8-bit machine, having 1111 1010.&lt;/li&gt;
&lt;li&gt;Add one, having 1111 1011. Then, 1111 1011 is the number repersenting -5 in 8-bit machine.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That is: &lt;br&gt;
&lt;strong&gt;2's complement = 1's complement + 1&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  7. Intro of Overflow and Underflow
&lt;/h3&gt;

&lt;p&gt;They happen when sum of 2 positive (or negative) number but get the negative (positive) number in machine, due to the fact that when machine has no more bit to extend to repersent this number.&lt;br&gt;
Overflow: Sum of 2 positive but get the negative&lt;br&gt;
Underflow: Sum of 2 negative but get the positive&lt;/p&gt;

&lt;h3&gt;
  
  
  8. Extension and Truncation between high-bit and low-bit
&lt;/h3&gt;

&lt;p&gt;This part would be the most important part of bit and byte chapter. I would like to go over this part in next post, because I think it would cost me few hours to design how to explain it in a comfortable way. &lt;/p&gt;




&lt;p&gt;Hope you like my post! You red heart or subsrcibtion are the energy of me! Thank you!&lt;/p&gt;

</description>
      <category>c</category>
      <category>computerscience</category>
      <category>systems</category>
    </item>
    <item>
      <title>Computer Systems Principles - Cp.1 Intro</title>
      <dc:creator>Yuehui Ruan</dc:creator>
      <pubDate>Tue, 25 Jan 2022 22:57:16 +0000</pubDate>
      <link>https://dev.to/divide_r_conquer/computer-systems-principles-cp1-2a80</link>
      <guid>https://dev.to/divide_r_conquer/computer-systems-principles-cp1-2a80</guid>
      <description>&lt;p&gt;This is the blog helping myself to review the knowledge that I have went over. Hope you all enjoy my summary.&lt;/p&gt;

&lt;p&gt;The knowledge is based on &lt;strong&gt;C language&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Chapter 1: Computer Systems Structure
&lt;/h2&gt;

&lt;p&gt;Before we dive into the deeper learning of computer system, the best way getting a comfortable start is to see the bigger picture of computer system structure. I think it is important for the beginner who just start learning Computer System or Operating System.&lt;/p&gt;

&lt;p&gt;Just like a hamburger, which has different layers like piece of bread, vagetables, beef, cheese and so on, computer systems also are dive into different layers. &lt;/p&gt;

&lt;p&gt;Layers in hamburger:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FRdbn8ko--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zzvcrw92ulp4h80gjye4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FRdbn8ko--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zzvcrw92ulp4h80gjye4.png" alt="Image description" width="880" height="602"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Layers in Computer Systems: &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--El-UyZFJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e8v3oyw5tqaxx9or2txz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--El-UyZFJ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e8v3oyw5tqaxx9or2txz.png" alt="Image description" width="880" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we can see, computer systems could be divided into three big layers, which are: (Up to down)&lt;br&gt;
1.Software Layers&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;All kinds of applications that we use daily&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;2.Operating System Layers&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Operating System -- A special application between software and hardware, which is used to transfer user's or applications' "codes" or "instructions" and then letting the hardware understand how to manipulate the menory.&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;3.Hardware Layers&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Including CPU, disks, registers, RAM and so on.&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Specially, and generally we can divede them into five main components (based on every single component could be dived deeper to study at the following chapters)&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Input/Output ports. (I/O ports)&lt;br&gt;
Enable the computer to take information or interations from its environment and dispaly them back to the user in some meaningful way.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Central processing unit. (CPU)&lt;br&gt;
Runs or executes instructions and computers data and memory addresses.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Random access memory (RAM)&lt;br&gt;
Stores the data and instructions of running programs. The data and instructions in RAM are typically lost when teh computer system loses power.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Secondary storage device (SSD)&lt;br&gt;
Hard disks or solid state drives (SSD) that can store programs and data even when power is not actively being provided to the computer.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Operating System (OS)&lt;br&gt;
A software layer that lies between the hardware of the computer and the software that a user runs on the computer.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;Next chapter, I will go over the , which is the basic knowledge in system, making you think like a computer. Hope you like it and subscribe it :)&lt;/p&gt;

</description>
      <category>systems</category>
      <category>computerscience</category>
      <category>c</category>
    </item>
    <item>
      <title>Three characteristics of OOP: Encapsulation</title>
      <dc:creator>Yuehui Ruan</dc:creator>
      <pubDate>Sat, 21 Aug 2021 06:22:00 +0000</pubDate>
      <link>https://dev.to/divide_r_conquer/3-main-characteristics-of-java-oop-language-class-2237</link>
      <guid>https://dev.to/divide_r_conquer/3-main-characteristics-of-java-oop-language-class-2237</guid>
      <description>&lt;h1&gt;
  
  
  Three main features of OOP language.
&lt;/h1&gt;




&lt;p&gt;PREFACE:&lt;br&gt;
(you can just skip this section to Introduction XD )&lt;/p&gt;

&lt;p&gt;Okay, Java and cpp are the language that I learn from my school, though this summer I receive an email from my professor that we "had better" to have some expreience on C. (And I use fews week to be acquainted with this. OMG) &lt;/p&gt;

&lt;p&gt;And, we know those two languages are &lt;strong&gt;Object Oriented Programming&lt;/strong&gt; languages. So they have three features that are different from Procedure-Oriented Language (like C, so far I have learnt). &lt;/p&gt;

&lt;p&gt;Due to these three features have a high occurrence rate on interviews from many comps, I decide to summary my knowledge. &lt;/p&gt;

&lt;p&gt;This blog is based on the language of JAVA, and you should know there are still difference amoung all OOP languages. And in this blog I will try to use "my word" and my thinking to describe what they are and why they exist, how to use them. Please correct me if there is any wrong in my blog. Thank you!&lt;/p&gt;


&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Encapsulation&lt;/li&gt;
&lt;li&gt;Inheritance&lt;/li&gt;
&lt;li&gt;Polymorphism&lt;/li&gt;
&lt;/ol&gt;


&lt;h3&gt;
  
  
  Encapsulation: What Why How
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;1. Defination (What):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Put the objects which have same features or, belongs to the same class together, and pack them well.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So you know in the company, there are lots of departments that led by different managers or supervisors. For example, we have &lt;code&gt;IT_Department&lt;/code&gt; class and &lt;code&gt;HR_Department&lt;/code&gt; class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HR_Department&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nc"&gt;Manager&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;Dep_Members&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;HR_Department&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;manager_name&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;&lt;span class="c1"&gt;// constructor of HR_Dep&lt;/span&gt;
        &lt;span class="nc"&gt;Manager&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;manager_name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;employ&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Our company need to employ a new employee."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;dismissal&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"We decide to dismissal someone..."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;IT_Department&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nc"&gt;Manager&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;Dep_Members&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;IT_Department&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;manager_name&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;&lt;span class="c1"&gt;// constructor of IT_Dep&lt;/span&gt;
        &lt;span class="nc"&gt;Manager&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;manager_name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Access_Database&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Our IT Department can access database of our company."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Power_outage&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"IT Department decide to shut down the power for fixing problems."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Google_Inc&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="n"&gt;IT_Department&lt;/span&gt; &lt;span class="n"&gt;it_Dep&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="n"&gt;HR_Department&lt;/span&gt; &lt;span class="n"&gt;hr_Dep&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;Google_Inc&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;IT_Manager_Name&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;HR_Manager_Name&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;&lt;span class="c1"&gt;// constructor of Google_Inc&lt;/span&gt;
        &lt;span class="n"&gt;it_Dep&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;IT_Department&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;IT_Manager_Name&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;hr_Dep&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;HR_Department&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="n"&gt;HR_Manager_Name&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Google Inc is established successfully!"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Test&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// set up a company call newGoogle_Inc XD&lt;/span&gt;
        &lt;span class="n"&gt;Google_Inc&lt;/span&gt; &lt;span class="n"&gt;google_Inc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Google_Inc&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Jack"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Rose"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are CEO of this company, you have to employ some managers to help you manage these different departments, and of course you require any department work in perfect order and help each other&lt;br&gt;
. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Significance (Why):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You can easily imagine that, how messy this scenario would be if we didn't have access to every piece of data in any class.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I believe, you can't stand it when HR employee turns off the power without checking in with THE IT department.  (even I never work for any companys XD) It's dangerous and out of line anywhere.&lt;/p&gt;

&lt;p&gt;So the existance of Encapsulation shows its importance right now. The example of company is also suitable for any program's, code's, data's management. It's dangerous  while after you design a program, some of your users could access your data and edit them. &lt;/p&gt;

&lt;p&gt;So for Java, we usually "pack" our CLASS (data) well through using &lt;strong&gt;&lt;em&gt;Permission Modifier&lt;/em&gt;&lt;/strong&gt;.&lt;br&gt;
   1.&lt;code&gt;public&lt;/code&gt;&lt;br&gt;
   2.&lt;code&gt;protected&lt;/code&gt; (default)&lt;br&gt;
   3.&lt;code&gt;private&lt;/code&gt; (most used to modify class and variable, as you can see on previous code block)&lt;/p&gt;

&lt;p&gt;Obviously, you can realize that, if you correctly use the &lt;br&gt;
permission modifier, you can realize the &lt;strong&gt;advantages&lt;/strong&gt; of your code:&lt;/p&gt;

&lt;p&gt;1.Isolate important variables(vars) or functions(funcs)&lt;br&gt;
2.Conveniently access vars or funcs&lt;br&gt;
3.Increase the importance&lt;br&gt;
4.Enhance the security&lt;/p&gt;

&lt;p&gt;And of course, these advantages also cause the code being much more harder to access and leading you spending more steps to access them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Implement of Encapsulation(HOW):&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Before using them, you need to know the range of different modified vars or funcs that could be accessed.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Modify&lt;/th&gt;
&lt;th&gt;Same class&lt;/th&gt;
&lt;th&gt;Same package&lt;/th&gt;
&lt;th&gt;Sub class&lt;/th&gt;
&lt;th&gt;All class&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;private&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;default&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;protected&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;public&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;td&gt;Yes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;In some way, &lt;code&gt;protected&lt;/code&gt; equals to default.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Eg: You can not access manager name of HR department directly by assign &lt;code&gt;=&lt;/code&gt;:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Favjpflv118l1irlqv0ne.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Favjpflv118l1irlqv0ne.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So, you need to set up some functions called "Getters" and "Setters":&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;IT_Department&lt;/span&gt;&lt;span class="o"&gt;{&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nc"&gt;Manager&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;Dep_Members&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;

    &lt;span class="n"&gt;IT_Department&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;manager_name&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;&lt;span class="c1"&gt;// constructor of IT_Dep&lt;/span&gt;
        &lt;span class="nc"&gt;Manager&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;manager_name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;getManager&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt; &lt;span class="c1"&gt;// a classic getter function&lt;/span&gt;
        &lt;span class="c1"&gt;//return manager's name&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;Manager&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;setManager&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;){&lt;/span&gt;&lt;span class="c1"&gt;// a classic setter function&lt;/span&gt;
        &lt;span class="c1"&gt;//set name to manager's name&lt;/span&gt;
        &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;Manager&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;

    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Access_Database&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Our IT Department can access database of our company."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;Power_outage&lt;/span&gt;&lt;span class="o"&gt;(){&lt;/span&gt;
        &lt;span class="nc"&gt;System&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"IT Department decide to shut down the power for fixing problems."&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hence, you can realize, the implement of encapsulation is abstract in code. We prefer to call encapsulation a phenomenon or a feature. If you have a clear and strict frame of code, your codes will look so GOOD and COMFORTABLE.&lt;/p&gt;

&lt;p&gt;In main function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;public&lt;/span&gt; &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// set up a company call newGoogle_Inc&lt;/span&gt;
        &lt;span class="n"&gt;Google_Inc&lt;/span&gt; &lt;span class="n"&gt;google_Inc&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;Google_Inc&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Jack"&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Rose"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;

        &lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;google_Inc&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;it_Dep&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;getManager&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; &lt;span class="c1"&gt;// assign "Jack" to name.&lt;/span&gt;
        &lt;span class="n"&gt;google_Inc&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;it_Dep&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;setManager&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Ben"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;&lt;span class="c1"&gt;// assign "Ben" to IT Department's manager&lt;/span&gt;
    &lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;Your advice and comments are the power of my moving forward. Thank you for your reading.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Never know how good you will be if you don't push yourself.&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
Ricky Ruan:&lt;/p&gt;

&lt;p&gt;E-mail: &lt;a href="mailto:yruan@umass.edu"&gt;yruan@umass.edu&lt;/a&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>oop</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
