<?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-5360944016602432340</id><updated>2024-09-28T13:55:47.693-07:00</updated><category term="Java"/><category term="OOP"/><category term="interview questions"/><category term="C++"/><category term="Interview Question"/><category term="C++ questions"/><category term="Hashtable"/><category term="C"/><category term="Interview"/><category term="Pointer"/><category term="Unix"/><category term="Abstract"/><category term="Basic Questions"/><category term="Convert String to Int"/><category term="Data Structure; Interview Question"/><category term="Facebook"/><category term="Final"/><category term="Hello World"/><category term="Investment Banks"/><category term="Linear time"/><category term="Map"/><category term="MapReduce"/><category term="Mircosoft"/><category term="Morgan Stanley"/><category term="PID"/><category term="Perl"/><category term="Server"/><category term="Shell"/><category term="Socket"/><category term="Static"/><category term="Trading system"/><category term="Tutorial"/><category term="XML"/><category term="algorithm"/><category term="encapsulation"/><category term="huge datasets"/><category term="inheritance"/><category term="longest palindrome substring"/><category term="memory"/><category term="operating systems"/><category term="polymorphism"/><title type='text'>Code Interview</title><subtitle type='html'>Code Interview, Technical Interview, Software Engineering Interview, C++ Programming, Java, Object Oriented Programming, Python Programming, Large dataset processing, Parallel Processing, Distributed Computing</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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>32</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-5803229433744362809</id><published>2012-05-28T22:13:00.000-07:00</published><updated>2012-05-28T22:13:25.911-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="algorithm"/><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview Question"/><category scheme="http://www.blogger.com/atom/ns#" term="Linear time"/><category scheme="http://www.blogger.com/atom/ns#" term="longest palindrome substring"/><title type='text'>Linear time algorithm for finding longest palindrome substring</title><content type='html'>&lt;br /&gt;
&lt;h2 style=&quot;background-color: white; color: #333333; font-family: Georgia, Verdana, Arial, serif; font-size: 1.4em; font-weight: normal; letter-spacing: 1px; line-height: 20px; margin: 1em 0px 0px; padding: 0px; text-align: left;&quot;&gt;
Linear time algorithm for finding&amp;nbsp;&lt;/h2&gt;
&lt;h2 style=&quot;background-color: white; color: #333333; font-family: Georgia, Verdana, Arial, serif; font-size: 1.4em; font-weight: normal; letter-spacing: 1px; line-height: 20px; margin: 1em 0px 0px; padding: 0px; text-align: left;&quot;&gt;
longest palindrome&amp;nbsp;substring&lt;/h2&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
Code in C++&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;div&gt;
char str[MAXSIZE];//pre-processed&amp;nbsp;array&lt;/div&gt;
&lt;div&gt;
int p[MAXSIZE]; //auxiliary array&lt;/div&gt;
&lt;div&gt;
char s[MAXSIZE];//original input&lt;/div&gt;
&lt;div&gt;
int n;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
void populatep()&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; int i;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; int mx = 0;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; int id;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; for(i=1; i&amp;lt;n; i++)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if( mx &amp;gt; i )&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; p[i] = MIN( p[2*id-i], p[id]+id-i );&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; else&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; p[i] = 1;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; for(; str[i+p[i]] == str[i-p[i]]; p[i]++)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if( p[i] + i &amp;gt; mx )&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mx = p[i] + i;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; id = i;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
void preprocess()&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; int i,j,k;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; n = strlen(s);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; str[0] = &#39;$&#39;;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; str[1] = &#39;#&#39;;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; for(i=0;i&amp;lt;n;i++)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; str[i*2 + 2] = s[i];&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; str[i*2 + 3] = &#39;#&#39;;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; n = n*2 + 2;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; str[n] = 0;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; cout &amp;lt;&amp;lt;str&amp;lt;&amp;lt;&quot; : &quot;&amp;lt;&amp;lt;strlen(str)&amp;lt;&amp;lt;endl;&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
void getlength()&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; int i;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; int ans = 0;&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; for(i=0;i&amp;lt;n;i++)&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; getmax(ans, p[i]);&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; printf(&quot;%d\n&quot;, ans-1);&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;div&gt;
//test&lt;/div&gt;
&lt;div&gt;
int main()&lt;/div&gt;
&lt;div&gt;
{&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; while( canf(&quot;%s&quot;, s) )&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; {&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; preprocess();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; populatep();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; getlength();&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; }&lt;/div&gt;
&lt;div&gt;
&amp;nbsp; &amp;nbsp; return 0;&lt;/div&gt;
&lt;div&gt;
}&lt;/div&gt;
&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;span style=&quot;background-color: white; color: #222222; line-height: 21px;&quot;&gt;For background, please read Wikipedia’s article about&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Longest_palindromic_substring&quot; style=&quot;background-color: white; border: 0px; color: #497ea8; line-height: 21px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;Longest Palindromic Substring&lt;/a&gt;&lt;span style=&quot;background-color: white; color: #222222; line-height: 21px;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;span style=&quot;color: #222222;&quot;&gt;&lt;span style=&quot;line-height: 21px;&quot;&gt;Relevant links:&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;a href=&quot;http://zhuhongcheng.wordpress.com/2009/08/02/a-simple-linear-time-algorithm-for-finding-longest-palindrome-sub-string/&quot; style=&quot;background-color: white; border: 0px; color: #497ea8; line-height: 21px; margin: 0px; outline: 0px; padding: 0px; text-decoration: none; vertical-align: baseline;&quot;&gt;A simple linear time algorithm for finding longest palindrome sub-string&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;a href=&quot;http://www.leetcode.com/2011/11/longest-palindromic-substring-part-ii.html#comment-20368&quot;&gt;http://www.leetcode.com/2011/11/longest-palindromic-substring-part-ii.html#comment-20368&lt;/a&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;a href=&quot;http://zhuhongcheng.wordpress.com/2009/08/02/a-simple-linear-time-algorithm-for-finding-longest-palindrome-sub-string/&quot;&gt;http://zhuhongcheng.wordpress.com/2009/08/02/a-simple-linear-time-algorithm-for-finding-longest-palindrome-sub-string/&lt;/a&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;Python implementation:&amp;nbsp;&lt;a href=&quot;http://www.akalin.cx/longest-palindrome-linear-time&quot;&gt;http://www.akalin.cx/longest-palindrome-linear-time&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, serif;&quot;&gt;A better emplanation in Chinese :&amp;nbsp;&lt;a href=&quot;http://blog.csdn.net/ggggiqnypgjg/article/details/6645824&quot;&gt;http://blog.csdn.net/ggggiqnypgjg/article/details/6645824&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/5803229433744362809/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2012/05/linear-time-algorithm-for-finding.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/5803229433744362809'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/5803229433744362809'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2012/05/linear-time-algorithm-for-finding.html' title='Linear time algorithm for finding longest palindrome substring'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-3553195889641798432</id><published>2012-05-28T21:41:00.001-07:00</published><updated>2012-05-28T21:52:55.988-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview Question"/><category scheme="http://www.blogger.com/atom/ns#" term="Pointer"/><title type='text'>How To Read C Declarations</title><content type='html'>&lt;br /&gt;
&lt;div class=&quot;wiki-content&quot; id=&quot;main-content&quot; style=&quot;background-color: white; border-bottom-color: rgb(221, 221, 221); border-bottom-style: solid; border-bottom-width: 1px; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; padding-bottom: 8px; text-align: left;&quot;&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
&lt;span style=&quot;font-size: 10pt; line-height: 13pt;&quot;&gt;Even experienced C programmers have difficulty reading declarations that go beyond simple arrays and pointers. For example, is the following an array of pointers or a pointer to an array?&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border: 1px dashed rgb(102, 153, 204); margin: 10px 20px; overflow: auto; padding: 0px;&quot;&gt;
&lt;div class=&quot;codeContent panelContent&quot; style=&quot;font-size: 0.95em; margin: 0px; padding: 12px 10px;&quot;&gt;
&lt;div class=&quot;syntaxhighlighter nogutter  java&quot; id=&quot;highlighter_734063&quot; style=&quot;font-size: 1em !important; margin: 1em 0px !important; overflow: auto !important; position: relative !important; width: 1787px;&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; clear: left; color: black; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; text-align: left !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 0px 0px 0em !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre-wrap !important; width: auto !important;&quot; title=&quot;Hint: double-click to select code&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;code class=&quot;java keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(51, 102, 153) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;*a[&lt;/code&gt;&lt;code class=&quot;java value&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 153, 0) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;10&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;];&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
What the heck does the following mean?&lt;/div&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border: 1px dashed rgb(102, 153, 204); margin: 10px 20px; overflow: auto; padding: 0px;&quot;&gt;
&lt;div class=&quot;codeContent panelContent&quot; style=&quot;font-size: 0.95em; margin: 0px; padding: 12px 10px;&quot;&gt;
&lt;div class=&quot;syntaxhighlighter nogutter  java&quot; id=&quot;highlighter_729583&quot; style=&quot;font-size: 1em !important; margin: 1em 0px !important; overflow: auto !important; position: relative !important; width: 1787px;&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; clear: left; color: black; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; text-align: left !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 0px 0px 0em !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre-wrap !important; width: auto !important;&quot; title=&quot;Hint: double-click to select code&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;code class=&quot;java keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(51, 102, 153) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;(*(*vtable)[])();&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
Naturally, it&#39;s a&amp;nbsp;&lt;em&gt;pointer to an array of pointers to functions returning integers&lt;/em&gt;.&amp;nbsp;&lt;img alt=&quot;(wink)&quot; class=&quot;emoticon emoticon-wink&quot; data-emoticon-name=&quot;wink&quot; src=&quot;http://www.antlr.org/wiki/s/en_GB/3148/5/_/images/icons/emoticons/wink.png&quot; style=&quot;background-image: none; background-position: initial initial; background-repeat: initial initial; border: 0px; height: auto; vertical-align: text-bottom; width: auto;&quot; /&gt;&lt;/div&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
This short article tells you how to read any C declaration correctly using a very simple technique. I am 99% certain that I read this in a book in the late 1980s, but I can&#39;t remember where. I doubt that I discovered this on my own (even though I&#39;ve always been delighted by computer language structure and esoterica). I do remember, however, building a simple program that would translate any declaration into English.&lt;/div&gt;
&lt;h2 id=&quot;HowToReadCDeclarations-Thegoldenrule&quot; style=&quot;border-bottom-color: rgb(102, 153, 204); font-size: 16pt; line-height: normal; margin: 21px 0px 4px; padding: 0px;&quot;&gt;



The golden rule&lt;/h2&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
The rule goes like this:&lt;/div&gt;
&lt;blockquote style=&quot;border-left-color: rgb(102, 153, 204); border-left-style: solid; border-left-width: 1px; font-size: 10pt; font-style: italic; margin: 10px 20px; padding: 0px 20px;&quot;&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
Start at the variable name (or innermost construct if no identifier&lt;br /&gt;
is present. Look right without jumping over a right parenthesis; say&lt;br /&gt;
what you see. Look left again without jumping over a parenthesis; say&lt;br /&gt;
what you see. Jump out a level of parentheses if any. Look right;&lt;br /&gt;
say what you see. Look left; say what you see. Continue in this&lt;br /&gt;
manner until you say the variable type or return type.&lt;/div&gt;
&lt;/blockquote&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
The degenerate case is:&lt;/div&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border: 1px dashed rgb(102, 153, 204); margin: 10px 20px; overflow: auto; padding: 0px;&quot;&gt;
&lt;div class=&quot;codeContent panelContent&quot; style=&quot;font-size: 0.95em; margin: 0px; padding: 12px 10px;&quot;&gt;
&lt;div class=&quot;syntaxhighlighter nogutter  java&quot; id=&quot;highlighter_179280&quot; style=&quot;font-size: 1em !important; margin: 1em 0px !important; overflow: auto !important; position: relative !important; width: 1787px;&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; clear: left; color: black; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; text-align: left !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 0px 0px 0em !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre-wrap !important; width: auto !important;&quot; title=&quot;Hint: double-click to select code&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;code class=&quot;java keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(51, 102, 153) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;i;&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
Starting at&amp;nbsp;&lt;code&gt;i&lt;/code&gt;&amp;nbsp;, you look right and find nothing. You look left and find the type&amp;nbsp;&lt;code&gt;int&lt;/code&gt;&amp;nbsp;, which you say. Done.&lt;/div&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
Ok, now a more complicated one:&lt;/div&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border: 1px dashed rgb(102, 153, 204); margin: 10px 20px; overflow: auto; padding: 0px;&quot;&gt;
&lt;div class=&quot;codeContent panelContent&quot; style=&quot;font-size: 0.95em; margin: 0px; padding: 12px 10px;&quot;&gt;
&lt;div class=&quot;syntaxhighlighter nogutter  java&quot; id=&quot;highlighter_198735&quot; style=&quot;font-size: 1em !important; margin: 1em 0px !important; overflow: auto !important; position: relative !important; width: 1787px;&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; clear: left; color: black; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; text-align: left !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 0px 0px 0em !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre-wrap !important; width: auto !important;&quot; title=&quot;Hint: double-click to select code&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;code class=&quot;java keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(51, 102, 153) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;*a[&lt;/code&gt;&lt;code class=&quot;java value&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 153, 0) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;3&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;];&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
Start at&amp;nbsp;&lt;code&gt;a&lt;/code&gt;&amp;nbsp;. Look right, say&amp;nbsp;&lt;em&gt;array of size 3&lt;/em&gt;. Look left and say&amp;nbsp;&lt;em&gt;pointer&lt;/em&gt;. Look right and see nothing. Look left and say&amp;nbsp;&lt;em&gt;int&lt;/em&gt;. All together you say&amp;nbsp;&lt;em&gt;a is an array of size 3 pointers to int&lt;/em&gt;.&lt;/div&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
Adding parentheses is when it gets weird:&lt;/div&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border: 1px dashed rgb(102, 153, 204); margin: 10px 20px; overflow: auto; padding: 0px;&quot;&gt;
&lt;div class=&quot;codeContent panelContent&quot; style=&quot;font-size: 0.95em; margin: 0px; padding: 12px 10px;&quot;&gt;
&lt;div class=&quot;syntaxhighlighter nogutter  java&quot; id=&quot;highlighter_685114&quot; style=&quot;font-size: 1em !important; margin: 1em 0px !important; overflow: auto !important; position: relative !important; width: 1787px;&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; clear: left; color: black; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; text-align: left !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 0px 0px 0em !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre-wrap !important; width: auto !important;&quot; title=&quot;Hint: double-click to select code&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;code class=&quot;java keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(51, 102, 153) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;(*a)[&lt;/code&gt;&lt;code class=&quot;java value&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(0, 153, 0) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;3&lt;/code&gt;&lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;];&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
The parentheses change the order just like in an expression. When you look right after&amp;nbsp;&lt;code&gt;a&lt;/code&gt;&amp;nbsp;, you see the right parenthesis, which you cannot jump over until you look left. Hence, you would say&amp;nbsp;&lt;em&gt;a is a pointer to an array of 3 ints&lt;/em&gt;.&lt;/div&gt;
&lt;h3 id=&quot;HowToReadCDeclarations-Functionpointers&quot; style=&quot;font-size: 14pt; line-height: normal; margin: 21px 0px 4px; padding: 0px;&quot;&gt;



Function pointers&lt;/h3&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
The C &quot;forward&quot; declaration:&lt;/div&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border: 1px dashed rgb(102, 153, 204); margin: 10px 20px; overflow: auto; padding: 0px;&quot;&gt;
&lt;div class=&quot;codeContent panelContent&quot; style=&quot;font-size: 0.95em; margin: 0px; padding: 12px 10px;&quot;&gt;
&lt;div class=&quot;syntaxhighlighter nogutter  java&quot; id=&quot;highlighter_700839&quot; style=&quot;font-size: 1em !important; margin: 1em 0px !important; overflow: auto !important; position: relative !important; width: 1787px;&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; clear: left; color: black; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; text-align: left !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 0px 0px 0em !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre-wrap !important; width: auto !important;&quot; title=&quot;Hint: double-click to select code&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;extern &lt;/code&gt;&lt;code class=&quot;java keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(51, 102, 153) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;foo();&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
just says that&amp;nbsp;&lt;em&gt;foo is a function returning int&lt;/em&gt;. This follows the same pattern for reading declarators as you saw in previous section. Start at&amp;nbsp;&lt;code&gt;foo&lt;/code&gt;&amp;nbsp;and look right. You see&amp;nbsp;&lt;code&gt;()&lt;/code&gt;&amp;nbsp;so say&amp;nbsp;&lt;em&gt;function&lt;/em&gt;. You look left and see&amp;nbsp;&lt;code&gt;int&lt;/code&gt;&amp;nbsp;. Say&amp;nbsp;&lt;em&gt;int&lt;/em&gt;.&lt;/div&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
Now, try this one:&lt;/div&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border: 1px dashed rgb(102, 153, 204); margin: 10px 20px; overflow: auto; padding: 0px;&quot;&gt;
&lt;div class=&quot;codeContent panelContent&quot; style=&quot;font-size: 0.95em; margin: 0px; padding: 12px 10px;&quot;&gt;
&lt;div class=&quot;syntaxhighlighter nogutter  java&quot; id=&quot;highlighter_24976&quot; style=&quot;font-size: 1em !important; margin: 1em 0px !important; overflow: auto !important; position: relative !important; width: 1787px;&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; clear: left; color: black; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; text-align: left !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 0px 0px 0em !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre-wrap !important; width: auto !important;&quot; title=&quot;Hint: double-click to select code&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;extern &lt;/code&gt;&lt;code class=&quot;java keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(51, 102, 153) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;*foo();&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
Yep, you say&amp;nbsp;&lt;em&gt;foo is a function returning a pointer to int&lt;/em&gt;.&lt;/div&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
Now for the big leap. Just like we can make a pointer to an&amp;nbsp;&lt;code&gt;int&lt;/code&gt;&amp;nbsp;or whatever, let&#39;s make a pointer to a function. In this case, we can drop the&amp;nbsp;&lt;code&gt;extern&lt;/code&gt;&amp;nbsp;as it&#39;s no longer a function forward reference, but a data variable declaration. Here is the basic pattern for function pointer:&lt;/div&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border: 1px dashed rgb(102, 153, 204); margin: 10px 20px; overflow: auto; padding: 0px;&quot;&gt;
&lt;div class=&quot;codeContent panelContent&quot; style=&quot;font-size: 0.95em; margin: 0px; padding: 12px 10px;&quot;&gt;
&lt;div class=&quot;syntaxhighlighter nogutter  java&quot; id=&quot;highlighter_281521&quot; style=&quot;font-size: 1em !important; margin: 1em 0px !important; overflow: auto !important; position: relative !important; width: 1787px;&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; clear: left; color: black; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; text-align: left !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 0px 0px 0em !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre-wrap !important; width: auto !important;&quot; title=&quot;Hint: double-click to select code&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;code class=&quot;java keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(51, 102, 153) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;(*foo)();&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
You start at&amp;nbsp;&lt;code&gt;foo&lt;/code&gt;&amp;nbsp;and see nothing to the right. So, to the left, you say&amp;nbsp;&lt;em&gt;pointer&lt;/em&gt;. Then to the right outside you see&amp;nbsp;&lt;em&gt;function&lt;/em&gt;. Then left you see&amp;nbsp;&lt;code&gt;int&lt;/code&gt;&amp;nbsp;. So you say&amp;nbsp;&lt;em&gt;foo is a pointer to a function returning int&lt;/em&gt;.&lt;/div&gt;
&lt;h3 id=&quot;HowToReadCDeclarations-Combinations&quot; style=&quot;font-size: 14pt; line-height: normal; margin: 21px 0px 4px; padding: 0px;&quot;&gt;



Combinations&lt;/h3&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
Here is&amp;nbsp;&lt;em&gt;an array of pointers to functions returning int&lt;/em&gt;, which we&#39;ll need for vtables below:&lt;/div&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border: 1px dashed rgb(102, 153, 204); margin: 10px 20px; overflow: auto; padding: 0px;&quot;&gt;
&lt;div class=&quot;codeContent panelContent&quot; style=&quot;font-size: 0.95em; margin: 0px; padding: 12px 10px;&quot;&gt;
&lt;div class=&quot;syntaxhighlighter nogutter  java&quot; id=&quot;highlighter_847984&quot; style=&quot;font-size: 1em !important; margin: 1em 0px !important; overflow: auto !important; position: relative !important; width: 1787px;&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; clear: left; color: black; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; text-align: left !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 0px 0px 0em !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre-wrap !important; width: auto !important;&quot; title=&quot;Hint: double-click to select code&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;code class=&quot;java keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(51, 102, 153) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;(*Object_vtable[])();&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
You need one last, incredibly bizarre declaration, for the lab:&lt;/div&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border: 1px dashed rgb(102, 153, 204); margin: 10px 20px; overflow: auto; padding: 0px;&quot;&gt;
&lt;div class=&quot;codeContent panelContent&quot; style=&quot;font-size: 0.95em; margin: 0px; padding: 12px 10px;&quot;&gt;
&lt;div class=&quot;syntaxhighlighter nogutter  java&quot; id=&quot;highlighter_360899&quot; style=&quot;font-size: 1em !important; margin: 1em 0px !important; overflow: auto !important; position: relative !important; width: 1787px;&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; clear: left; color: black; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; text-align: left !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 0px 0px 0em !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre-wrap !important; width: auto !important;&quot; title=&quot;Hint: double-click to select code&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;code class=&quot;java keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(51, 102, 153) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;(*(*vtable)[])();&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
This is the pointer to the vtable you will need in each &quot;object&quot; you define.&lt;/div&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
This pointer to a vtable is set to the address of a vtable; for example,&amp;nbsp;&lt;code&gt;&amp;amp;Truck_vtable&lt;/code&gt;&amp;nbsp;.&lt;/div&gt;
&lt;h2 id=&quot;HowToReadCDeclarations-Summary&quot; style=&quot;border-bottom-color: rgb(102, 153, 204); font-size: 16pt; line-height: normal; margin: 21px 0px 4px; padding: 0px;&quot;&gt;



Summary&lt;/h2&gt;
&lt;div style=&quot;font-size: 10pt; line-height: 13pt; margin-bottom: 10px; padding: 0px;&quot;&gt;
The following examples summarize the cases needed for building virtual tables ala C++ to implement polymorphism (like the original&amp;nbsp;&lt;code&gt;cfront&lt;/code&gt;&amp;nbsp;C++ to C translator).&lt;/div&gt;
&lt;div class=&quot;code panel&quot; style=&quot;border: 1px dashed rgb(102, 153, 204); margin: 10px 20px 0px; overflow: auto; padding: 0px;&quot;&gt;
&lt;div class=&quot;codeContent panelContent&quot; style=&quot;font-size: 0.95em; margin: 0px; padding: 12px 10px;&quot;&gt;
&lt;div class=&quot;syntaxhighlighter nogutter  java&quot; id=&quot;highlighter_752334&quot; style=&quot;font-size: 1em !important; margin: 1em 0px !important; overflow: auto !important; position: relative !important; width: 1787px;&quot;&gt;
&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; clear: left; color: black; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; text-align: left !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;tbody style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;tr style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;&lt;td class=&quot;code&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: 1787px;&quot;&gt;&lt;div class=&quot;container&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 0px 0px 0em !important; position: relative !important; right: auto !important; top: auto !important; vertical-align: baseline !important; white-space: pre-wrap !important; width: auto !important;&quot; title=&quot;Hint: double-click to select code&quot;&gt;
&lt;div class=&quot;line number1 index0 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;code class=&quot;java keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(51, 102, 153) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;*ptr_to_int;&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number2 index1 alt1&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;code class=&quot;java keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(51, 102, 153) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;*func_returning_ptr_to_int();&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number3 index2 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;code class=&quot;java keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(51, 102, 153) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;(*ptr_to_func_returning_int)();&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number4 index3 alt1&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;code class=&quot;java keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(51, 102, 153) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;(*array_of_ptr_to_func_returning_int[])();&lt;/code&gt;&lt;/div&gt;
&lt;div class=&quot;line number5 index4 alt2&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px 1em 0px 0em !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;
&lt;code class=&quot;java keyword&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; color: rgb(51, 102, 153) !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; font-weight: bold !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;java plain&quot; style=&quot;background-image: none !important; border-bottom-left-radius: 0px !important; border-bottom-right-radius: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border: 0px !important; bottom: auto !important; box-sizing: content-box !important; float: none !important; font-family: Consolas, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, Courier, monospace !important; font-size: 1em !important; height: auto !important; left: auto !important; line-height: 1.2em !important; margin: 0px !important; min-height: inherit !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important;&quot;&gt;(*(*ptr_to_an_array_of_ptr_to_func_returning_int)[])();&lt;/code&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;pageSection group&quot; id=&quot;labels-section&quot; style=&quot;background-color: white; font-family: Arial, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 17px; margin: 20px 0px 0px; text-align: left;&quot;&gt;
&lt;div class=&quot;labels-editor&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; &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; Source: click &lt;a href=&quot;http://www.antlr.org/wiki/display/CS652/How+To+Read+C+Declarations&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;&amp;nbsp; &amp;nbsp;Author&amp;nbsp;&lt;a class=&quot;external-link&quot; href=&quot;http://www.cs.usfca.edu/~parrt&quot; rel=&quot;nofollow&quot; style=&quot;color: #326ca6; outline: none;&quot;&gt;Terence Parr&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;The great advice from&amp;nbsp;&lt;a href=&quot;http://stackoverflow.com/users/134554/john-bode&quot; style=&quot;background-color: white; border: 0px; color: #4a6b82; cursor: pointer; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; margin: 0px; padding: 0px; vertical-align: baseline; white-space: nowrap;&quot;&gt;John Bode&lt;/a&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;border: 0px; clear: both; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
It&#39;s easier to remember the rule as absent any explicit grouping,&amp;nbsp;&lt;code style=&quot;background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline;&quot;&gt;()&lt;/code&gt;&amp;nbsp;and&amp;nbsp;&lt;code style=&quot;background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline;&quot;&gt;[]&lt;/code&gt;&amp;nbsp;bind before&amp;nbsp;&lt;code style=&quot;background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline;&quot;&gt;*&lt;/code&gt;. Thus, for a declaration like&lt;/div&gt;
&lt;pre class=&quot;lang-c prettyprint&quot; style=&quot;background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;&quot;&gt;&lt;code style=&quot;border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;T &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;];&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; clear: both; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
the&amp;nbsp;&lt;code style=&quot;background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline;&quot;&gt;[]&lt;/code&gt;&amp;nbsp;bind before the&amp;nbsp;&lt;code style=&quot;background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline;&quot;&gt;*&lt;/code&gt;, so&amp;nbsp;&lt;code style=&quot;background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline;&quot;&gt;a&lt;/code&gt;&amp;nbsp;is an N-element array of pointer. Breaking it down in steps:&lt;/div&gt;
&lt;pre class=&quot;lang-c prettyprint&quot; style=&quot;background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;&quot;&gt;&lt;code style=&quot;border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp; &amp;nbsp;a &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; a
&amp;nbsp; &amp;nbsp;a&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; is an N&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;element array
&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; of pointer
T &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; to T&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; clear: both; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
For a declaration like&lt;/div&gt;
&lt;pre class=&quot;lang-c prettyprint&quot; style=&quot;background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;&quot;&gt;&lt;code style=&quot;border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;T &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(*&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;];&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; clear: both; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
the parens force the&amp;nbsp;&lt;code style=&quot;background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline;&quot;&gt;*&lt;/code&gt;&amp;nbsp;to bind before the&amp;nbsp;&lt;code style=&quot;background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; margin: 0px; padding: 1px 5px; vertical-align: baseline;&quot;&gt;[]&lt;/code&gt;, so&lt;/div&gt;
&lt;pre class=&quot;lang-c prettyprint&quot; style=&quot;background-color: #eeeeee; border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; font-size: 14px; line-height: 18px; margin-bottom: 10px; max-height: 600px; overflow: auto; padding: 5px; vertical-align: baseline; width: auto;&quot;&gt;&lt;code style=&quot;border: 0px; font-family: Consolas, Menlo, Monaco, &#39;Lucida Console&#39;, &#39;Liberation Mono&#39;, &#39;DejaVu Sans Mono&#39;, &#39;Bitstream Vera Sans Mono&#39;, &#39;Courier New&#39;, monospace, serif; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp; &amp;nbsp; a &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; a
&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(*&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &amp;nbsp; &amp;nbsp; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; is a pointer
&amp;nbsp; &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(*&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; to an N&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;element array
T &lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;(*&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;)[&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; &amp;nbsp;&lt;/span&gt;&lt;span class=&quot;pun&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;pln&quot; style=&quot;background-color: transparent; border: 0px; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt; of T&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;div style=&quot;border: 0px; clear: both; font-family: Arial, &#39;Liberation Sans&#39;, &#39;DejaVu Sans&#39;, sans-serif; font-size: 14px; line-height: 18px; margin-bottom: 1em; padding: 0px; vertical-align: baseline; word-wrap: break-word;&quot;&gt;
It&#39;s still the clockwise/spiral rule, just expressed in a more compact manner.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/3553195889641798432/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2012/05/how-to-read-c-declarations.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/3553195889641798432'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/3553195889641798432'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2012/05/how-to-read-c-declarations.html' title='How To Read C Declarations'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-6384763425642486157</id><published>2012-04-27T17:37:00.000-07:00</published><updated>2012-05-28T21:38:47.499-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Abstract"/><category scheme="http://www.blogger.com/atom/ns#" term="Final"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview Question"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="OOP"/><category scheme="http://www.blogger.com/atom/ns#" term="Static"/><title type='text'>Java Interview Frequently Asked Questions &amp; Answers (S1P2</title><content type='html'>&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwIMfdUZdqM5dj8rRYbiC523X4p6b9SMs79EIvANzyUprX1G2_h7g5qiSfJbYdfjyMJNfXyDWBagyNeiiMv5Bo-EmZGyauFsW3UlLcfO0J1h3ePkC3AL5vfVNa5ntX6o297VN6pC2nbmk/s1600/title.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;60&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiwIMfdUZdqM5dj8rRYbiC523X4p6b9SMs79EIvANzyUprX1G2_h7g5qiSfJbYdfjyMJNfXyDWBagyNeiiMv5Bo-EmZGyauFsW3UlLcfO0J1h3ePkC3AL5vfVNa5ntX6o297VN6pC2nbmk/s320/title.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;
&lt;span style=&quot;color: #333333; font-family: &#39;Helvetica Neue Light&#39;, HelveticaNeue-Light, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 20px;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;h1 class=&quot;title entry-title&quot; itemprop=&quot;name&quot; style=&quot;background-color: white; color: #333333; display: table-cell; font-family: &#39;Helvetica Neue Light&#39;, HelveticaNeue-Light, &#39;Helvetica Neue&#39;, Helvetica, Arial, sans-serif; font-size: 20px; font-weight: normal; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 40px; padding-top: 0px; position: relative; text-align: center; vertical-align: middle; width: 710px;&quot;&gt;



&lt;/h1&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;Difference between
Vector and ArrayList?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Vector
is synchronized whereas arraylist is not.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;Difference between
Swing and Awt?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AWT
are heavy-weight components. Swings are light-weight components. Hence swing
works faster than AWT.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;What is the
difference between a constructor and a method?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A
constructor is a member function of a class that is used to create objects of
that class. It has the same name as the class itself, has no return type, and
is invoked using the new operator. A method is an ordinary member function of a
class. It has its own name, a return type (which may be void), and is invoked
using the dot operator.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;What is an Iterator?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Some
of the collection classes provide traversal of their contents via a
java.util.Iterator interface. This interface allows you to walk through a
collection of objects, operating on each object in turn. Remember when using
Iterators that they contain a snapshot of the collection at the time the
Iterator was obtained; generally it is not advisable to modify the collection
itself while traversing an Iterator. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; State
the significance of public, private, protected, default modifiers both singly
and in combination and state the effect of package relationships on declared
items qualified by these modifiers.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public
: Public class is visible in other packages, field is visible everywhere (class
must be public too)&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;text-indent: .5in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;private : Private variables or methods may be used
only by an instance of the same class that declares the variable or method, A
private feature may only be accessed by the class that owns the feature.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;text-indent: .5in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;protected : Is available to all classes in the same
package and also available to all subclasses of the class that owns the
protected feature. This access is provided even to subclasses that reside in a
different package from the class that owns the protected feature.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;text-indent: .5in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;default :What you get by default, i.e., without any
access modifier (i.e., &amp;nbsp;public private or
protected).It means that it is visible to all within a particular package.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot; style=&quot;text-indent: .5in;&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;What is an abstract
class?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Abstract
class must be extended/sub-classed (to be useful). It serves as a template. A
class that is abstract may not be instantiated (i.e., you may not call its
constructor), abstract class may contain static data. Any class with an
abstract method is automatically abstract itself, and must be declared as such.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;A class may be declared abstract even if it has no abstract methods. This
prevents it from being instantiated.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;What is static in
java?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Static
means one per class, not one for each object no matter how many instance of a
class might exist. This means that you can use them without creating an
instance of a class.Static methods are implicitly final, because overriding is
done based on the type of the object, and static methods are attached to a
class, not an object. A static method in a superclass can be shadowed by
another static method in a subclass, as long as the original method was not
declared final. However, you can&#39;t override a static method with a nonstatic
method. In other words, you can&#39;t change a static method into an instance method
in a subclass.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;What is final?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; A
final class can&#39;t be extended ie., final class may not be subclassed. A final
method can&#39;t be overridden when its class is inherited. You can&#39;t change value
of a final variable (is a constant).&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 18px;&quot;&gt;Source:&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.allapplabs.com/interview_questions/java_interview_questions.htm&quot; style=&quot;font-family: Verdana, sans-serif; line-height: 18px;&quot; target=&quot;_blank&quot;&gt;Here&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/6384763425642486157/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2012/04/java-interview-frequently-asked_5759.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/6384763425642486157'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/6384763425642486157'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2012/04/java-interview-frequently-asked_5759.html' title='Java Interview Frequently Asked Questions &amp; Answers (S1P2'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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/AVvXsEiwIMfdUZdqM5dj8rRYbiC523X4p6b9SMs79EIvANzyUprX1G2_h7g5qiSfJbYdfjyMJNfXyDWBagyNeiiMv5Bo-EmZGyauFsW3UlLcfO0J1h3ePkC3AL5vfVNa5ntX6o297VN6pC2nbmk/s72-c/title.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-3430495647201985300</id><published>2012-04-27T17:32:00.000-07:00</published><updated>2012-04-27T17:32:25.432-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Hashtable"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview Question"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="OOP"/><title type='text'>Java Interview Frequently Asked Questions &amp; Answers (S1P1)</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhG9cxUUPghiRA7X253DdNgBZgJHoSrMR4-NXBu0RX267vkQDL98g7ogAtXrIwwQAt87mDj1R8YqEgw2YBj0IMOp1jhjal3cb23FAkyejEhrTy7QCpAOaVSJOXFrWflM9F_xKkO_SYVr-c/s1600/logo0.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhG9cxUUPghiRA7X253DdNgBZgJHoSrMR4-NXBu0RX267vkQDL98g7ogAtXrIwwQAt87mDj1R8YqEgw2YBj0IMOp1jhjal3cb23FAkyejEhrTy7QCpAOaVSJOXFrWflM9F_xKkO_SYVr-c/s200/logo0.png&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;What is the
difference between an Interface and an Abstract class?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; An
abstract class can have instance methods that implement a default behavior. An
Interface can only declare constants and instance methods, but cannot implement
default behavior and all methods are implicitly abstract. An interface has all
public members and no implementation. An abstract class is a class which may
have the usual flavors of class members (private, protected, etc.), but has
some abstract methods.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;What is the purpose
of garbage collection in Java, and when is it used?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The
purpose of garbage collection is to identify and discard objects that are no
longer needed by a program so that their resources can be reclaimed and reused.
A Java object is subject to garbage collection when it becomes unreachable to
the program in which it is used.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;Describe
synchronization in respect to multithreading.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; With
respect to multithreading, synchronization is the capability to control the
access of multiple threads to shared resources. Without synchronization, it is
possible for one thread to modify a shared variable while another thread is in
the process of using or updating same shared variable. This usually leads to
significant errors. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;Explain different way
of using thread?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The
thread could be implemented by using runable interface or by inheriting from
the Thread class. The former is more advantageous, because when you are going
for multiple inheritance, the only interface can help.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;What are pass by
reference and pass by value?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Pass
By Reference means the passing the address itself rather than passing the
value. Pass by Value means passing a copy of the value to be passed. &lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;What is HashMap and
Map?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Map
is Interface and Hashmap is class that implements that.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;Difference between
HashMap and HashTable?&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; The
HashMap class is roughly equivalent to Hashtable, except that it is
unsynchronized and permits nulls. (HashMap allows null values as key and value
whereas Hashtable does not allow). HashMap does not guarantee that the order of
the map will remain constant over time. HashMap is unsynchronized and Hashtable
is synchronized.&lt;span style=&quot;font-size: x-small;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;
&lt;span style=&quot;font-family: Verdana, sans-serif; line-height: 115%;&quot;&gt;Source: &lt;a href=&quot;http://www.allapplabs.com/interview_questions/java_interview_questions.htm&quot; target=&quot;_blank&quot;&gt;Here&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/3430495647201985300/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2012/04/java-interview-frequently-asked_27.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/3430495647201985300'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/3430495647201985300'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2012/04/java-interview-frequently-asked_27.html' title='Java Interview Frequently Asked Questions &amp; Answers (S1P1)'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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/AVvXsEhG9cxUUPghiRA7X253DdNgBZgJHoSrMR4-NXBu0RX267vkQDL98g7ogAtXrIwwQAt87mDj1R8YqEgw2YBj0IMOp1jhjal3cb23FAkyejEhrTy7QCpAOaVSJOXFrWflM9F_xKkO_SYVr-c/s72-c/logo0.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-8742188146050554363</id><published>2012-04-26T18:21:00.001-07:00</published><updated>2012-04-27T17:02:09.420-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="OOP"/><title type='text'>Java Interview Frequently Asked Questions &amp; Answers (Part Six)</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtspAArrxgBwlrxe2dtBgi96sYahtcleBFbzsZHl9I7biYgzfNH3ZALvRgBh4BakXJOIZ9Fjx9shkjlUoZ8TovLKhiQINvKO7NNs1D3kMFBzPAq0hZpjeqrZZwaxSd8YEwI1Q2WogwTPE/s1600/title.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;38&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtspAArrxgBwlrxe2dtBgi96sYahtcleBFbzsZHl9I7biYgzfNH3ZALvRgBh4BakXJOIZ9Fjx9shkjlUoZ8TovLKhiQINvKO7NNs1D3kMFBzPAq0hZpjeqrZZwaxSd8YEwI1Q2WogwTPE/s200/title.png&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;ol style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; list-style-image: initial; list-style-position: initial; margin-bottom: 18px; margin-left: 3em; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is RMI architecture?&lt;/b&gt;- RMI architecture consists of four layers and each layer performs specific functions: a) Application layer - contains the actual object definition. b) Proxy layer - consists of stub and skeleton. c) Remote Reference layer - gets the stream of bytes from the transport layer and sends it to the proxy layer. d) Transportation layer - responsible for handling the actual machine-to-machine communication.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;what is UnicastRemoteObject?&lt;/b&gt;- All remote objects must extend UnicastRemoteObject, which provides functionality that is needed to make objects available from remote machines.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;Explain the methods, rebind() and lookup() in Naming class?&lt;/b&gt;- rebind() of the Naming class(found in java. rmi) is used to update the RMI registry on the server machine. Naming. rebind(”AddSever”, AddServerImpl); lookup() of the Naming class accepts one argument, the rmi URL and returns a reference to an object of type AddServerImpl.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is a Java Bean?&lt;/b&gt;- A Java Bean is a software component that has been designed to be reusable in a variety of different environments.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is a Jar file?&lt;/b&gt;- Jar file allows to efficiently deploying a set of classes and their associated resources. The elements in a jar file are compressed, which makes downloading a Jar file much faster than separately downloading several uncompressed files. The package java. util. zip contains classes that read and write jar files.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is BDK?&lt;/b&gt;- BDK, Bean Development Kit is a tool that enables to create, configure and connect a set of set of Beans and it can be used to test Beans without writing a code.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is JSP?&lt;/b&gt;- JSP is a dynamic scripting capability for web pages that allows Java as well as a few special tags to be embedded into a web file (HTML/XML, etc). The suffix traditionally ends with .jsp to indicate to the web server that the file is a JSP files. JSP is a server side technology - you can’t do any client side validation with it. The advantages are: a) The JSP assists in making the HTML more functional. Servlets on the other hand allow outputting of HTML but it is a tedious process. b) It is easy to make a change and then let the JSP capability of the web server you are using deal with compiling it into a servlet and running it.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are JSP scripting elements?&lt;/b&gt;- JSP scripting elements lets to insert Java code into the servlet that will be generated from the current JSP page. There are three forms: a) Expressions of the form &amp;lt;%= expression %&amp;gt; that are evaluated and inserted into the output, b) Scriptlets of the form&amp;lt;% code %&amp;gt;that are inserted into the servlet’s service method, and c) Declarations of the form &amp;lt;%! Code %&amp;gt;that are inserted into the body of the servlet class, outside of any existing methods.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are JSP Directives?&lt;/b&gt;- A JSP directive affects the overall structure of the servlet class. It usually has the following form:&amp;lt;%@ directive attribute=”value” %&amp;gt; However, you can also combine multiple attribute settings for a single directive, as follows:&amp;lt;%@ directive attribute1=”value1″ attribute 2=”value2″ . . . attributeN =”valueN” %&amp;gt; There are two main types of directive: page, which lets to do things like import classes, customize the servlet superclass, and the like; and include, which lets to insert a file into the servlet class at the time the JSP file is translated into a servlet&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are Predefined variables or implicit objects?&lt;/b&gt;- To simplify code in JSP expressions and scriptlets, we can use eight automatically defined variables, sometimes called implicit objects. They are request, response, out, session, application, config, pageContext, and page.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are JSP ACTIONS?&lt;/b&gt;- JSP actions use constructs in XML syntax to control the behavior of the servlet engine. You can dynamically insert a file, reuse JavaBeans components, forward the user to another page, or generate HTML for the Java plugin. Available actions include: jsp:include - Include a file at the time the page is requested. jsp:useBean - Find or instantiate a JavaBean. jsp:setProperty - Set the property of a JavaBean. jsp:getProperty - Insert the property of a JavaBean into the output. jsp:forward - Forward the requester to a newpage. Jsp: plugin - Generate browser-specific code that makes an OBJECT or EMBED&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;How do you pass data (including JavaBeans) to a JSP from a servlet?&lt;/b&gt;- (1) Request Lifetime: Using this technique to pass beans, a request dispatcher (using either “include” or forward”) can be called. This bean will disappear after processing this request has been completed. Servlet: request. setAttribute(”theBean”, myBean); RequestDispatcher rd = getServletContext(). getRequestDispatcher(”thepage. jsp”); rd. forward(request, response); JSP PAGE:&amp;lt;jsp: useBean id=”theBean” scope=”request” class=”. . . . . ” /&amp;gt;(2) Session Lifetime: Using this technique to pass beans that are relevant to a particular session (such as in individual user login) over a number of requests. This bean will disappear when the session is invalidated or it times out, or when you remove it. Servlet: HttpSession session = request. getSession(true); session. putValue(”theBean”, myBean); /* You can do a request dispatcher here, or just let the bean be visible on the next request */ JSP Page:&amp;lt;jsp:useBean id=”theBean” scope=”session” class=”. . . ” /&amp;gt; 3) Application Lifetime: Using this technique to pass beans that are relevant to all servlets and JSP pages in a particular app, for all users. For example, I use this to make a JDBC connection pool object available to the various servlets and JSP pages in my apps. This bean will disappear when the servlet engine is shut down, or when you remove it. Servlet: GetServletContext(). setAttribute(”theBean”, myBean); JSP PAGE:&amp;lt;jsp:useBean id=”theBean” scope=”application” class=”. . . ” /&amp;gt;&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;How can I set a cookie in JSP?&lt;/b&gt;- response. setHeader(”Set-Cookie”, “cookie string”); To give the response-object to a bean, write a method setResponse (HttpServletResponse response) - to the bean, and in jsp-file:&amp;lt;% bean. setResponse (response); %&amp;gt;&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;How can I delete a cookie with JSP?&lt;/b&gt;- Say that I have a cookie called “foo, ” that I set a while ago &amp;amp; I want it to go away. I simply: &amp;lt;% Cookie killCookie = new Cookie(”foo”, null); KillCookie. setPath(”/”); killCookie. setMaxAge(0); response. addCookie(killCookie); %&amp;gt;&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;How are Servlets and JSP Pages related?&lt;/b&gt;- JSP pages are focused around HTML (or XML) with Java codes and JSP tags inside them. When a web server that has JSP support is asked for a JSP page, it checks to see if it has already compiled the page into a servlet. Thus, JSP pages become servlets and are transformed into pure Java and then compiled, loaded into the server and executed.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, serif; font-size: 12px; line-height: 18px;&quot;&gt;Source:Click&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.techinterviews.com/master-list-of-java-interview-questions&quot; style=&quot;font-family: Georgia, serif; font-size: 12px; line-height: 18px;&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/8742188146050554363/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2012/04/java-interview-frequently-asked_5306.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/8742188146050554363'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/8742188146050554363'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2012/04/java-interview-frequently-asked_5306.html' title='Java Interview Frequently Asked Questions &amp; Answers (Part Six)'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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/AVvXsEjtspAArrxgBwlrxe2dtBgi96sYahtcleBFbzsZHl9I7biYgzfNH3ZALvRgBh4BakXJOIZ9Fjx9shkjlUoZ8TovLKhiQINvKO7NNs1D3kMFBzPAq0hZpjeqrZZwaxSd8YEwI1Q2WogwTPE/s72-c/title.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-6658771031730113305</id><published>2012-04-26T18:20:00.000-07:00</published><updated>2012-04-26T18:20:00.131-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="OOP"/><title type='text'>Java Interview Frequently Asked Questions &amp; Answers (Part Five)</title><content type='html'>&lt;br /&gt;
&lt;ol style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; list-style-image: initial; list-style-position: initial; margin-bottom: 18px; margin-left: 3em; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between an applet and a servlet?&lt;/b&gt;- a) Servlets are to servers what applets are to browsers. b) Applets must have graphical user interfaces whereas servlets have no graphical user interfaces.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between doPost and doGet methods?&lt;/b&gt;- a) doGet() method is used to get information, while doPost() method is used for posting information. b) doGet() requests can’t send large amount of information and is limited to 240-255 characters. However, doPost()requests passes all of its data, of unlimited length. c) A doGet() request is appended to the request URL in a query string and this allows the exchange is visible to the client, whereas a doPost() request passes directly over the socket connection as part of its HTTP request body and the exchange are invisible to the client.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the life cycle of a servlet?&lt;/b&gt;- Each Servlet has the same life cycle: a) A server loads and initializes the servlet by init () method. b) The servlet handles zero or more client’s requests through service() method. c) The server removes the servlet through destroy() method.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;Who is loading the init() method of servlet?&lt;/b&gt;- Web server&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are the different servers available for developing and deploying Servlets?&lt;/b&gt;- a) Java Web Server b) JRun g) Apache Server h) Netscape Information Server i) Web Logic&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;How many ways can we track client and what are they?&lt;/b&gt;- The servlet API provides two ways to track client state and they are: a) Using Session tracking and b) Using Cookies.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is session tracking and how do you track a user session in servlets?&lt;/b&gt;- Session tracking is a mechanism that servlets use to maintain state about a series requests from the same user across some period of time. The methods used for session tracking are: a) User Authentication - occurs when a web server restricts access to some of its resources to only those clients that log in using a recognized username and password. b) Hidden form fields - fields are added to an HTML form that are not displayed in the client’s browser. When the form containing the fields is submitted, the fields are sent back to the server. c) URL rewriting - every URL that the user clicks on is dynamically modified or rewritten to include extra information. The extra information can be in the form of extra path information, added parameters or some custom, server-specific URL change. d) Cookies - a bit of information that is sent by a web server to a browser and which can later be read back from that browser. e) HttpSession- places a limit on the number of sessions that can exist in memory. This limit is set in the session. maxresidents property.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is Server-Side Includes (SSI)?&lt;/b&gt;- Server-Side Includes allows embedding servlets within HTML pages using a special servlet tag. In many servlets that support servlets, a page can be processed by the server to include output from servlets at certain points inside the HTML page. This is accomplished using a special internal SSINCLUDE, which processes the servlet tags. SSINCLUDE servlet will be invoked whenever a file with an. shtml extension is requested. So HTML files that include server-side includes must be stored with an . shtml extension.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are cookies and how will you use them?&lt;/b&gt;- Cookies are a mechanism that a servlet uses to have a client hold a small amount of state-information associated with the user. a) Create a cookie with the Cookie constructor: public Cookie(String name, String value) b) A servlet can send a cookie to the client by passing a Cookie object to the addCookie() method of HttpServletResponse: public void HttpServletResponse. addCookie(Cookie cookie) c) A servlet retrieves cookies by calling the getCookies() method of HttpServletRequest: public Cookie[ ] HttpServletRequest. getCookie().&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;Is it possible to communicate from an applet to servlet and how many ways and how?&lt;/b&gt;- Yes, there are three ways to communicate from an applet to servlet and they are: a) HTTP Communication(Text-based and object-based) b) Socket Communication c) RMI Communication&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is connection pooling?&lt;/b&gt;- With servlets, opening a database connection is a major bottleneck because we are creating and tearing down a new connection for every page request and the time taken to create connection will be more. Creating a connection pool is an ideal approach for a complicated servlet. With a connection pool, we can duplicate only the resources we need to duplicate rather than the entire servlet. A connection pool can also intelligently manage the size of the pool and make sure each connection remains valid. A number of connection pool packages are currently available. Some like DbConnectionBroker are freely available from Java Exchange Works by creating an object that dispenses connections and connection Ids on request. The ConnectionPool class maintains a Hastable, using Connection objects as keys and Boolean values as stored values. The Boolean value indicates whether a connection is in use or not. A program calls getConnection() method of the ConnectionPool for getting Connection object it can use; it calls returnConnection() to give the connection back to the pool.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;Why should we go for interservlet communication?&lt;/b&gt;- Servlets running together in the same server communicate with each other in several ways. The three major reasons to use interservlet communication are: a) Direct servlet manipulation - allows to gain access to the other currently loaded servlets and perform certain tasks (through the ServletContext object) b) Servlet reuse - allows the servlet to reuse the public methods of another servlet. c) Servlet collaboration - requires to communicate with each other by sharing specific information (through method invocation)&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;Is it possible to call servlet with parameters in the URL?&lt;/b&gt;- Yes. You can call a servlet with parameters in the syntax as (?Param1 = xxx || m2 = yyy).&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is Servlet chaining?&lt;/b&gt;- Servlet chaining is a technique in which two or more servlets can cooperate in servicing a single request. In servlet chaining, one servlet’s output is piped to the next servlet’s input. This process continues until the last servlet is reached. Its output is then sent back to the client.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;How do servlets handle multiple simultaneous requests?&lt;/b&gt;- The server has multiple threads that are available to handle requests. When a request comes in, it is assigned to a thread, which calls a service method (for example: doGet(), doPost() and service()) of the servlet. For this reason, a single servlet object can have its service methods called by many threads at once.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between TCP/IP and UDP?&lt;/b&gt;- TCP/IP is a two-way communication between the client and the server and it is a reliable and there is a confirmation regarding reaching the message to the destination. It is like a phone call. UDP is a one-way communication only between the client and the server and it is not a reliable and there is no confirmation regarding reaching the message to the destination. It is like a postal mail.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is Inet address?&lt;/b&gt;- Every computer connected to a network has an IP address. An IP address is a number that uniquely identifies each computer on the Net. An IP address is a 32-bit number.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is Domain Naming Service(DNS)?&lt;/b&gt;- It is very difficult to remember a set of numbers(IP address) to connect to the Internet. The Domain Naming Service(DNS) is used to overcome this problem. It maps one particular IP address to a string of characters. For example, www. mascom. com implies com is the domain name reserved for US commercial sites, moscom is the name of the company and www is the name of the specific computer, which is mascom’s server.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is URL?&lt;/b&gt;- URL stands for Uniform Resource Locator and it points to resource files on the Internet. URL has four components: http://www. address. com:80/index.html, where http - protocol name, address - IP address or host name, 80 - port number and index.html - file path.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is RMI and steps involved in developing an RMI object?&lt;/b&gt;- Remote Method Invocation (RMI) allows java object that executes on one machine and to invoke the method of a Java object to execute on another machine. The steps involved in developing an RMI object are: a) Define the interfaces b) Implementing these interfaces c) Compile the interfaces and their implementations with the java compiler d) Compile the server implementation with RMI compiler e) Run the RMI registry f) Run the application.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, serif; font-size: 12px; line-height: 18px;&quot;&gt;Source:Click&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.techinterviews.com/master-list-of-java-interview-questions&quot; style=&quot;font-family: Georgia, serif; font-size: 12px; line-height: 18px;&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/6658771031730113305/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2012/04/java-interview-frequently-asked_5279.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/6658771031730113305'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/6658771031730113305'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2012/04/java-interview-frequently-asked_5279.html' title='Java Interview Frequently Asked Questions &amp; Answers (Part Five)'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-430539255313988131</id><published>2012-04-26T18:18:00.004-07:00</published><updated>2012-04-26T18:18:50.078-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="OOP"/><title type='text'>Java Interview Frequently Asked Questions &amp; Answers (Part Four)</title><content type='html'>&lt;br /&gt;
&lt;ol style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; list-style-image: initial; list-style-position: initial; margin-bottom: 18px; margin-left: 3em; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;Which containers use a Border layout as their default layout?&lt;/b&gt;- Window, Frame and Dialog classes use a BorderLayout as their layout.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;Which containers use a Flow layout as their default layout?&lt;/b&gt;- Panel and Applet classes use the FlowLayout as their default layout.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are wrapper classes?&lt;/b&gt;- Wrapper classes are classes that allow primitive types to be accessed as objects.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are Vector, Hashtable, LinkedList and Enumeration?&lt;/b&gt;- Vector : The Vector class provides the capability to implement a growable array of objects. Hashtable : The Hashtable class implements a Hashtable data structure. A Hashtable indexes and stores objects in a dictionary using hash codes as the object’s keys. Hash codes are integer values that identify objects. LinkedList: Removing or inserting elements in the middle of an array can be done using LinkedList. A LinkedList stores each object in a separate link whereas an array stores object references in consecutive locations. Enumeration: An object that implements the Enumeration interface generates a series of elements, one at a time. It has two methods, namely hasMoreElements() and nextElement(). HasMoreElemnts() tests if this enumeration has more elements and nextElement method returns successive elements of the series.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between set and list?&lt;/b&gt;- Set stores elements in an unordered way but does not contain duplicate elements, whereas list stores elements in an ordered way but may contain duplicate elements.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is a stream and what are the types of Streams and classes of the Streams?&lt;/b&gt;- A Stream is an abstraction that either produces or consumes information. There are two types of Streams and they are: Byte Streams: Provide a convenient means for handling input and output of bytes. Character Streams: Provide a convenient means for handling input &amp;amp; output of characters. Byte Streams classes: Are defined by using two abstract classes, namely InputStream and OutputStream. Character Streams classes: Are defined by using two abstract classes, namely Reader and Writer.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between Reader/Writer and InputStream/Output Stream?&lt;/b&gt;- The Reader/Writer class is character-oriented and the InputStream/OutputStream class is byte-oriented.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is an I/O filter?&lt;/b&gt;- An I/O filter is an object that reads from one stream and writes to another, usually altering the data in some way as it is passed from one stream to another.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is serialization and deserialization?&lt;/b&gt;- Serialization is the process of writing the state of an object to a byte stream. Deserialization is the process of restoring these objects.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is JDBC?&lt;/b&gt;- JDBC is a set of Java API for executing SQL statements. This API consists of a set of classes and interfaces to enable programs to write pure Java Database applications.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are drivers available?&lt;/b&gt;- a) JDBC-ODBC Bridge driver b) Native API Partly-Java driver c) JDBC-Net Pure Java driver d) Native-Protocol Pure Java driver&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between JDBC and ODBC?&lt;/b&gt;- a) OBDC is for Microsoft and JDBC is for Java applications. b) ODBC can’t be directly used with Java because it uses a C interface. c) ODBC makes use of pointers which have been removed totally from Java. d) ODBC mixes simple and advanced features together and has complex options for simple queries. But JDBC is designed to keep things simple while allowing advanced capabilities when required. e) ODBC requires manual installation of the ODBC driver manager and driver on all client machines. JDBC drivers are written in Java and JDBC code is automatically installable, secure, and portable on all platforms. f) JDBC API is a natural Java interface and is built on ODBC. JDBC retains some of the basic features of ODBC.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are the types of JDBC Driver Models and explain them?&lt;/b&gt;- There are two types of JDBC Driver Models and they are: a) Two tier model and b) Three tier model Two tier model: In this model, Java applications interact directly with the database. A JDBC driver is required to communicate with the particular database management system that is being accessed. SQL statements are sent to the database and the results are given to user. This model is referred to as client/server configuration where user is the client and the machine that has the database is called as the server. Three tier model: A middle tier is introduced in this model. The functions of this model are: a) Collection of SQL statements from the client and handing it over to the database, b) Receiving results from database to the client and c) Maintaining control over accessing and updating of the above.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are the steps involved for making a connection with a database or how do you connect to a database?&lt;/b&gt;a) Loading the driver : To load the driver, Class. forName() method is used. Class. forName(”sun. jdbc. odbc. JdbcOdbcDriver”); When the driver is loaded, it registers itself with the java. sql. DriverManager class as an available database driver. b) Making a connection with database: To open a connection to a given database, DriverManager. getConnection() method is used. Connection con = DriverManager. getConnection (”jdbc:odbc:somedb”, “user”, “password”); c) Executing SQL statements : To execute a SQL query, java. sql. statements class is used. createStatement() method of Connection to obtain a new Statement object. Statement stmt = con. createStatement(); A query that returns data can be executed using the executeQuery() method of Statement. This method executes the statement and returns a java. sql. ResultSet that encapsulates the retrieved data: ResultSet rs = stmt. executeQuery(”SELECT * FROM some table”); d) Process the results : ResultSet returns one row at a time. Next() method of ResultSet object can be called to move to the next row. The getString() and getObject() methods are used for retrieving column values: while(rs. next()) { String event = rs. getString(”event”); Object count = (Integer) rs. getObject(”count”);&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What type of driver did you use in project?&lt;/b&gt;- JDBC-ODBC Bridge driver (is a driver that uses native(C language) libraries and makes calls to an existing ODBC driver to access a database engine).&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are the types of statements in JDBC?&lt;/b&gt;- Statement: to be used createStatement() method for executing single SQL statement PreparedStatement — To be used preparedStatement() method for executing same SQL statement over and over. CallableStatement — To be used prepareCall() method for multiple SQL statements over and over.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is stored procedure?&lt;/b&gt;- Stored procedure is a group of SQL statements that forms a logical unit and performs a particular task. Stored Procedures are used to encapsulate a set of operations or queries to execute on database. Stored procedures can be compiled and executed with different parameters and results and may have any combination of input/output parameters.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;How to create and call stored procedures?&lt;/b&gt;- To create stored procedures: Create procedure procedurename (specify in, out and in out parameters) BEGIN Any multiple SQL statement; END; To call stored procedures: CallableStatement csmt = con. prepareCall(”{call procedure name(?,?)}”); csmt. registerOutParameter(column no. , data type); csmt. setInt(column no. , column name) csmt. execute();&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is servlet?&lt;/b&gt;- Servlets are modules that extend request/response-oriented servers, such as java-enabled web servers. For example, a servlet might be responsible for taking data in an HTML order-entry form and applying the business logic used to update a company’s order database.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, serif; font-size: 12px; line-height: 18px;&quot;&gt;Source:Click&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.techinterviews.com/master-list-of-java-interview-questions&quot; style=&quot;font-family: Georgia, serif; font-size: 12px; line-height: 18px;&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/430539255313988131/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2012/04/java-interview-frequently-asked_3123.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/430539255313988131'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/430539255313988131'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2012/04/java-interview-frequently-asked_3123.html' title='Java Interview Frequently Asked Questions &amp; Answers (Part Four)'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-4843499181529494667</id><published>2012-04-26T18:13:00.003-07:00</published><updated>2012-04-26T18:13:42.056-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="OOP"/><title type='text'>Java Interview Frequently Asked Questions &amp; Answers (Part Three)</title><content type='html'>&lt;br /&gt;
&lt;ol style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; list-style-image: initial; list-style-position: initial; margin-bottom: 18px; margin-left: 3em; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is synchronization?&lt;/b&gt;- Synchronization is the mechanism that ensures that only one thread is accessed the resources at a time.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;When you will synchronize a piece of your code?&lt;/b&gt;- When you expect your code will be accessed by different threads and these threads may change a particular data causing data corruption.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is deadlock?&lt;/b&gt;- When two threads are waiting each other and can’t precede the program is said to be deadlock.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is daemon thread and which method is used to create the daemon thread?&lt;/b&gt;- Daemon thread is a low priority thread which runs intermittently in the back ground doing the garbage collection operation for the java runtime system. setDaemon method is used to create a daemon thread.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;Are there any global variables in Java, which can be accessed by other part of your program?&lt;/b&gt;- No, it is not the main method in which you define variables. Global variables is not possible because concept of encapsulation is eliminated here.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is an applet?&lt;/b&gt;- Applet is a dynamic and interactive program that runs inside a web page displayed by a java capable browser.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between applications and applets?&lt;/b&gt;- a)Application must be run on local machine whereas applet needs no explicit installation on local machine. b)Application must be run explicitly within a java-compatible virtual machine whereas applet loads and runs itself automatically in a java-enabled browser. d)Application starts execution with its main method whereas applet starts execution with its init method. e)Application can run with or without graphical user interface whereas applet must run within a graphical user interface.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;How does applet recognize the height and width?&lt;/b&gt;- Using getParameters() method.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;When do you use codebase in applet?&lt;/b&gt;- When the applet class file is not in the same directory, codebase is used.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the lifecycle of an applet?&lt;/b&gt;- init() method - Can be called when an applet is first loaded start() method - Can be called each time an applet is started. paint() method - Can be called when the applet is minimized or maximized. stop() method - Can be used when the browser moves off the applet’s page. destroy() method - Can be called when the browser is finished with the applet.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;How do you set security in applets?&lt;/b&gt;- using setSecurityManager() method&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is an event and what are the models available for event handling?&lt;/b&gt;- An event is an event object that describes a state of change in a source. In other words, event occurs when an action is generated, like pressing button, clicking mouse, selecting a list, etc. There are two types of models for handling events and they are: a) event-inheritance model and b) event-delegation model&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are the advantages of the model over the event-inheritance model?&lt;/b&gt;- The event-delegation model has two advantages over the event-inheritance model. They are: a)It enables event handling by objects other than the ones that generate the events. This allows a clean separation between a component’s design and its use. b)It performs much better in applications where many events are generated. This performance improvement is due to the fact that the event-delegation model does not have to be repeatedly process unhandled events as is the case of the event-inheritance.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is source and listener?&lt;/b&gt;- source : A source is an object that generates an event. This occurs when the internal state of that object changes in some way. listener : A listener is an object that is notified when an event occurs. It has two major requirements. First, it must have been registered with one or more sources to receive notifications about specific types of events. Second, it must implement methods to receive and process these notifications.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is adapter class?&lt;/b&gt;- An adapter class provides an empty implementation of all methods in an event listener interface. Adapter classes are useful when you want to receive and process only some of the events that are handled by a particular event listener interface. You can define a new class to act listener by extending one of the adapter classes and implementing only those events in which you are interested. For example, the MouseMotionAdapter class has two methods, mouseDragged()and mouseMoved(). The signatures of these empty are exactly as defined in the MouseMotionListener interface. If you are interested in only mouse drag events, then you could simply extend MouseMotionAdapter and implement mouseDragged() .&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is meant by controls and what are different types of controls in AWT?&lt;/b&gt;- Controls are components that allow a user to interact with your application and the AWT supports the following types of controls: Labels, Push Buttons, Check Boxes, Choice Lists, Lists, Scrollbars, Text Components. These controls are subclasses of Component.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between choice and list?&lt;/b&gt;- A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices and only one item may be selected from a choice. A List may be displayed in such a way that several list items are visible and it supports the selection of one or more list items.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between scrollbar and scrollpane?&lt;/b&gt;- A Scrollbar is a Component, but not a Container whereas Scrollpane is a Conatiner and handles its own events and perform its own scrolling.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is a layout manager and what are different types of layout managers available in java AWT?&lt;/b&gt;- A layout manager is an object that is used to organize components in a container. The different layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout and GridBagLayout.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;How are the elements of different layouts organized?&lt;/b&gt;- FlowLayout: The elements of a FlowLayout are organized in a top to bottom, left to right fashion. BorderLayout: The elements of a BorderLayout are organized at the borders (North, South, East and West) and the center of a container. CardLayout: The elements of a CardLayout are stacked, on top of the other, like a deck of cards. GridLayout: The elements of a GridLayout are of equal size and are laid out using the square of a grid. GridBagLayout: The elements of a GridBagLayout are organized according to a grid. However, the elements are of different size and may occupy more than one row or column of the grid. In addition, the rows and columns may have different sizes.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, serif; font-size: 12px; line-height: 18px;&quot;&gt;Source:Click&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.techinterviews.com/master-list-of-java-interview-questions&quot; style=&quot;font-family: Georgia, serif; font-size: 12px; line-height: 18px;&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/4843499181529494667/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2012/04/java-interview-frequently-asked_26.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/4843499181529494667'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/4843499181529494667'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2012/04/java-interview-frequently-asked_26.html' title='Java Interview Frequently Asked Questions &amp; Answers (Part Three)'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-6204554320075266056</id><published>2012-04-25T16:35:00.001-07:00</published><updated>2012-04-26T18:21:18.513-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="OOP"/><title type='text'>Java Interview Frequently Asked Questions &amp; Answers (Part Two)</title><content type='html'>&lt;br /&gt;
&lt;ol style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; list-style-image: initial; list-style-position: initial; margin-bottom: 18px; margin-left: 3em; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is meant by Inheritance and what are its advantages?&lt;/b&gt;- Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by subclasses.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between this() and super()?&lt;/b&gt;- this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between superclass and subclass?&lt;/b&gt;- A super class is a class that is inherited whereas sub class is a class that does the inheriting.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What modifiers may be used with top-level class?&lt;/b&gt;- public, abstract and final can be used for top-level class.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are inner class and anonymous class?&lt;/b&gt;- Inner class : classes defined in other classes, including those defined in methods are called inner classes. An inner class can have any accessibility including private. Anonymous class : Anonymous class is a class defined inside a method without a name and is instantiated and declared in the same place and cannot have explicit constructors.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is a package?&lt;/b&gt;- A package is a collection of classes and interfaces that provides a high-level layer of access protection and name space management.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is a reflection package?&lt;/b&gt;- java. lang. reflect package has the ability to analyze itself in runtime.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is interface and its use?&lt;/b&gt;- Interface is similar to a class which may contain method’s signature only but not bodies and it is a formal set of method and constant declarations that must be defined by the class that implements it. Interfaces are useful for: a)Declaring methods that one or more classes are expected to implement b)Capturing similarities between unrelated classes without forcing a class relationship. c)Determining an object’s programming interface without revealing the actual body of the class.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is an abstract class?&lt;/b&gt;- An abstract class is a class designed with implementation gaps for subclasses to fill in and is deliberately incomplete.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between Integer and int?&lt;/b&gt;- a) Integer is a class defined in the java. lang package, whereas int is a primitive data type defined in the Java language itself. Java does not automatically convert from one to the other. b) Integer can be used as an argument for a method that requires an object, whereas int can be used for calculations.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is a cloneable interface and how many methods does it contain?&lt;/b&gt;- It is not having any method because it is a TAGGED or MARKER interface.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between abstract class and interface?&lt;/b&gt;- a) All the methods declared inside an interface are abstract whereas abstract class must have at least one abstract method and others may be concrete or abstract. b) In abstract class, key word abstract must be used for the methods whereas interface we need not use that keyword for the methods. c) Abstract class must have subclasses whereas interface can’t have subclasses.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;Can you have an inner class inside a method and what variables can you access?&lt;/b&gt;- Yes, we can have an inner class inside a method and final variables can be accessed.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between String and String Buffer?&lt;/b&gt;- a) String objects are constants and immutable whereas StringBuffer objects are not. b) String class supports constant strings whereas StringBuffer class supports growable and modifiable strings.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between Array and vector?&lt;/b&gt;- Array is a set of related data type and static whereas vector is a growable array of objects and dynamic.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between exception and error?&lt;/b&gt;- The exception class defines mild error conditions that your program encounters. Exceptions can occur when trying to open the file, which does not exist, the network connection is disrupted, operands being manipulated are out of prescribed ranges, the class file you are interested in loading is missing. The error class defines serious error conditions that you should not attempt to recover from. In most cases it is advisable to let the program terminate when such an error is encountered.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between process and thread?&lt;/b&gt;- Process is a program in execution whereas thread is a separate path of execution in a program.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is multithreading and what are the methods for inter-thread communication and what is the class in which these methods are defined?&lt;/b&gt;- Multithreading is the mechanism in which more than one thread run independent of each other within the process. wait (), notify () and notifyAll() methods can be used for inter-thread communication and these methods are in Object class. wait() : When a thread executes a call to wait() method, it surrenders the object lock and enters into a waiting state. notify() or notifyAll() : To remove a thread from the waiting state, some other thread must make a call to notify() or notifyAll() method on the same object.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the class and interface in java to create thread and which is the most advantageous method?&lt;/b&gt;- Thread class and Runnable interface can be used to create threads and using Runnable interface is the most advantageous method to create threads because we need not extend thread class here.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are the states associated in the thread?&lt;/b&gt;- Thread contains ready, running, waiting and dead states.&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, serif; font-size: 12px; line-height: 18px;&quot;&gt;Source:Click&amp;nbsp;&lt;/span&gt;&lt;a href=&quot;http://www.techinterviews.com/master-list-of-java-interview-questions&quot; style=&quot;font-family: Georgia, serif; font-size: 12px; line-height: 18px;&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/6204554320075266056/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2012/04/java-interview-frequently-asked_25.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/6204554320075266056'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/6204554320075266056'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2012/04/java-interview-frequently-asked_25.html' title='Java Interview Frequently Asked Questions &amp; Answers (Part Two)'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-3086993274995815765</id><published>2012-04-25T16:30:00.004-07:00</published><updated>2012-04-25T16:37:41.618-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="OOP"/><title type='text'>Java Interview Frequently Asked Questions &amp; Answers (Part One)</title><content type='html'>&lt;br /&gt;
&lt;ol style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; font-family: Georgia, serif; font-size: 12px; line-height: 18px; list-style-image: initial; list-style-position: initial; margin-bottom: 18px; margin-left: 3em; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between procedural and object-oriented programs?&lt;/b&gt;- a) In procedural program, programming logic follows certain procedures and the instructions are executed one after another. In OOP program, unit of program is object, which is nothing but combination of data and code. b) In procedural program, data is exposed to the whole program whereas in OOPs program, it is accessible with in the object and which in turn assures the security of the code.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are Encapsulation, Inheritance and Polymorphism?&lt;/b&gt;- Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse. Inheritance is the process by which one object acquires the properties of another object. Polymorphism is the feature that allows one interface to be used for general class actions.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between Assignment and Initialization?&lt;/b&gt;- Assignment can be done as many times as desired whereas initialization can be done only once.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is OOPs?&lt;/b&gt;&lt;span style=&quot;background-color: transparent;&quot;&gt;- Object oriented programming organizes a program around its data, i. e. , objects and a set of well defined interfaces to that data. An object-oriented program can be characterized as data controlling access to code.&lt;/span&gt;&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are Class, Constructor and Primitive data types?&lt;/b&gt;- Class is a template for multiple objects with similar features and it is a blue print for objects. It defines a type of object according to the data the object can hold and the operations the object can perform. Constructor is a special kind of method that determines how an object is initialized when created. Primitive data types are 8 types and they are: byte, short, int, long, float, double, boolean, char.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is an Object and how do you allocate memory to it?&lt;/b&gt;- Object is an instance of a class and it is a software unit that combines a structured set of data with a set of operations for inspecting and manipulating that data. When an object is created using new operator, memory is allocated to it.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between constructor and method?&lt;/b&gt;- Constructor will be automatically invoked when an object is created whereas method has to be called explicitly.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are methods and how are they defined?&lt;/b&gt;- Methods are functions that operate on instances of classes in which they are defined. Objects can communicate with each other using methods and can call methods in other classes. Method definition has four parts. They are name of the method, type of object or primitive type the method returns, a list of parameters and the body of the method. A method’s signature is a combination of the first three parts mentioned above.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the use of bin and lib in JDK?&lt;/b&gt;- Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is casting?&lt;/b&gt;- Casting is used to convert the value of one type to another.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;How many ways can an argument be passed to a subroutine and explain them?&lt;/b&gt;- An argument can be passed in two ways. They are passing by value and passing by reference. Passing by value: This method copies the value of an argument into the formal parameter of the subroutine. Passing by reference: In this method, a reference to an argument (not the value of the argument) is passed to the parameter.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is the difference between an argument and a parameter?&lt;/b&gt;- While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are different types of access modifiers?&lt;/b&gt;- public: Any thing declared as public can be accessed from anywhere. private: Any thing declared as private can’t be seen outside of its class. protected: Any thing declared as protected can be accessed by classes in the same package and subclasses in the other packages. default modifier : Can be accessed only to classes in the same package.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is final, finalize() and finally?&lt;/b&gt;- final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method can’t be overridden. A final variable can’t change from its initialized value. finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection. finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown. For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. This finally keyword is designed to address this contingency.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is UNICODE?&lt;/b&gt;- Unicode is used for internal representation of characters and strings and it uses 16 bits to represent each other.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is Garbage Collection and how to call it explicitly?&lt;/b&gt;- When an object is no longer referred to by any variable, java automatically reclaims memory used by that object. This is known as garbage collection. System. gc() method may be used to call it explicitly.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is finalize() method?&lt;/b&gt;- finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What are Transient and Volatile Modifiers?&lt;/b&gt;- Transient: The transient modifier applies to variables only and it is not stored as part of its object’s Persistent state. Transient variables are not serialized. Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is method overloading and method overriding?&lt;/b&gt;- Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading. Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.&lt;/li&gt;
&lt;li style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;&lt;b style=&quot;background-attachment: initial; background-clip: initial; background-color: transparent; background-image: initial; background-origin: initial; border-bottom-width: 0px; border-color: initial; border-image: initial; border-left-width: 0px; border-right-width: 0px; border-style: initial; border-top-width: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; outline-color: initial; outline-style: initial; outline-width: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: baseline;&quot;&gt;What is difference between overloading and overriding?&lt;/b&gt;- a) In overloading, there is a relationship between methods available in the same class whereas in overriding, there is relationship between a superclass method and subclass method. b) Overloading does not block inheritance from the superclass whereas overriding blocks inheritance from the superclass. c) In overloading, separate methods share the same name whereas in overriding, subclass method replaces the superclass. d) Overloading must have different method signatures whereas overriding must have same signature.&lt;/li&gt;
&lt;/ol&gt;
&lt;div&gt;
&lt;span style=&quot;font-family: Georgia, serif;&quot;&gt;&lt;span style=&quot;font-size: 12px; line-height: 18px;&quot;&gt;Source:Click &lt;a href=&quot;http://www.techinterviews.com/master-list-of-java-interview-questions&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/3086993274995815765/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2012/04/java-interview-frequently-asked.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/3086993274995815765'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/3086993274995815765'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2012/04/java-interview-frequently-asked.html' title='Java Interview Frequently Asked Questions &amp; Answers (Part One)'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-6601154200336682731</id><published>2012-03-24T18:04:00.000-07:00</published><updated>2012-03-24T18:04:03.592-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="OOP"/><title type='text'>C++ frequently asked questions (4)</title><content type='html'>&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is multiple inheritance(virtual inheritance)? What are its advantages and disadvantages?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Multiple Inheritance is the process whereby a child can be derived from more than one parent class. The advantage of multiple inheritance is that it allows a class to inherit the functionality of more than one base class thus allowing for modeling of complex relationships. The disadvantage of multiple inheritance is that it can lead to a lot of confusion(ambiguity) when two base classes implement a method with the same name.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What are the differences between a C++ struct and C++ class?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The default member and base class access specifiers are different.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The C++ struct has all the features of the class. The only differences are that a struct defaults to public member access and public base class inheritance, and a class defaults to the private access specifier and private base class inheritance.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What are the access privileges in C++? What is the default access level?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The access privileges in C++ are private, public and protected. The default access level assigned to members of a class is private. Private members of a class are accessible only within the class and by friends of the class. Protected members are accessible by the class itself and it&#39;s sub-classes. Public members of a class can be accessed by anyone.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is a nested class? Why can it be useful?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A nested class is a class enclosed within the scope of another class. For example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;// Example 1: Nested class&lt;br /&gt;
//&lt;br /&gt;
class OuterClass&lt;br /&gt;
{&lt;br /&gt;
class NestedClass&lt;br /&gt;
{&lt;br /&gt;
// ...&lt;br /&gt;
};&lt;br /&gt;
// ...&lt;br /&gt;
};&lt;br /&gt;
Nested classes are useful for organizing code and controlling access and dependencies. Nested classes obey access rules just like other parts of a class do; so, in Example 1, if NestedClass is public then any code can name it as OuterClass::NestedClass. Often nested classes contain private implementation details, and are therefore made private; in Example 1, if NestedClass is private, then only OuterClass&#39;s members and friends can use NestedClass.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 12pt;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;When you instantiate as outer class, it won&#39;t instantiate inside class.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is a local class? Why can it be useful?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;local class is a class defined within the scope of a function -- any function, whether a member function or a free function. For example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 12pt;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;// Example 2: Local class&lt;br /&gt;
//&lt;br /&gt;
int f()&lt;br /&gt;
{&lt;br /&gt;
class LocalClass&lt;br /&gt;
{&lt;br /&gt;
// ...&lt;br /&gt;
};&lt;br /&gt;
// ...&lt;br /&gt;
};&lt;br /&gt;
Like nested classes, local classes can be a useful tool for managing code dependencies.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Can a copy constructor accept an object of the same class as parameter, instead of reference of the object?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;No. It is specified in the definition of the copy constructor itself. It should generate an error if a programmer specifies a copy constructor with a first argument that is an object and not a reference.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: Arial, sans-serif;&quot;&gt;&lt;span style=&quot;font-size: 15px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/6601154200336682731/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2012/03/c-frequently-asked-questions-4.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/6601154200336682731'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/6601154200336682731'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2012/03/c-frequently-asked-questions-4.html' title='C++ frequently asked questions (4)'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-4861472299233985465</id><published>2012-03-24T18:02:00.000-07:00</published><updated>2012-03-24T18:02:25.718-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="memory"/><category scheme="http://www.blogger.com/atom/ns#" term="Pointer"/><title type='text'>C++ frequently asked questions (3) - Pointer and Memory management</title><content type='html'>&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is Memory alignment??&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 12pt;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The term alignment primarily means the tendency of an address pointer value to be a multiple of some power of two. So a pointer with two byte alignment has a zero in the least significant bit. And a pointer with four byte alignment has a zero in both the two least significant bits. And so on. More alignment means a longer sequence of zero bits in the lowest bits of a pointer.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What problem does the namespace feature solve?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Multiple providers of libraries might use common global identifiers causing a name collision when an application tries to link with two or more such libraries. The namespace feature surrounds a library&#39;s external declarations with a unique namespace that eliminates the potential for those collisions.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;namespace [identifier] { namespace-body }&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A namespace declaration identifies and assigns a name to a declarative region.&lt;br /&gt;
The identifier in a namespace declaration must be unique in the declarative region in which it is used. The identifier is the name of the namespace and is used to reference its members.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is an Iterator class?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A class that is used to traverse through the objects maintained by a container class. There are five categories of iterators: input iterators, output iterators, forward iterators, bidirectional iterators, random access. An iterator is an entity that gives access to the contents of a container object without violating encapsulation constraints. Access to the contents is granted on a one-at-a-time basis in order. The order can be storage order (as in lists and queues) or some arbitrary order (as in array indices) or according to some ordering relation (as in an ordered binary tree). The iterator is a construct, which provides an interface that, when called, yields either the next element in the container, or some value denoting the fact that there are no more elements to examine. Iterators hide the details of access to and update of the elements of a container class. Something like a pointer.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is the use of &#39;using&#39; declaration?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A using declaration makes it possible to use a name from a namespace without the scope operator.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is a dangling pointer?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A dangling pointer arises when you use the address of an object after its lifetime is over. This may occur in situations like returning addresses of the automatic variables from a function or using the address of the memory block after it is freed.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What do you mean by Stack unwinding?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;It is a process during exception handling when the destructor is called for all local objects in the stack between the place where the exception was thrown and where it is caught.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Name the operators that cannot be overloaded??&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 12pt;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;sizeof, ., .*, .-&amp;gt;, ::, ?:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is overloading??&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;With the C++ language, you can overload functions and operators. Overloading is the practice of supplying more than one definition for a given function name in the same scope.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 12pt;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;- Any two functions in a set of overloaded functions must have different argument lists.&lt;br /&gt;
- Overloading functions with argument lists of the same types, based on return type alone, is an error.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is inline function??&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The __inline keyword tells the compiler to substitute the code within the function definition for every instance of a function call. However, substitution occurs only at the compiler&#39;s discretion. For example, the compiler does not inline a function if its address is taken or if it is too large to inline.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is a container class? What are the types of container classes?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A container class is a class that is used to hold objects in memory or external storage. A container class acts as a generic holder. A container class has a predefined behavior and a well-known interface. A container class is a supporting class whose purpose is to hide the topology used for maintaining the list of objects in memory. When a container class contains a group of mixed objects, the container is called a heterogeneous container; when the container is holding a group of objects that are all the same, the container is called a homogeneous container.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is Overriding?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;To override a method, a subclass of the class that originally declared the method must declare a method with the same name, return type (or a subclass of that return type), and same parameter list.&lt;br /&gt;
The definition of the method overriding is:&lt;br /&gt;
· Must have same method name.&lt;br /&gt;
· Must have same data type.&lt;br /&gt;
· Must have same argument list.&lt;br /&gt;
Overriding a method means that replacing a method functionality in child class. To imply overriding functionality we need parent and child classes. In the child class you define the same method signature as one defined in the parent class.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is &quot;this&quot; pointer?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The this pointer is a pointer accessible only within the member functions of a class, struct, or union type. It points to the object for which the member function is called. Static member functions do not have a this pointer.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;When a nonstatic member function is called for an object, the address of the object is passed as a hidden argument to the function. For example, the following function call&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;myDate.setMonth( 3 );&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;can be interpreted this way:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;setMonth( &amp;amp;myDate, 3 );&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The object&#39;s address is available from within the member function as the this pointer. It is legal, though unnecessary, to use the this pointer when referring to members of the class.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;How virtual functions are implemented C++?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Virtual functions are implemented using a table of function pointers, called the vtable. There is one entry in the table per virtual function in the class. This table is created by the constructor of the class. When a derived class is constructed, its base class is constructed first which creates the vtable. If the derived class overrides any of the base classes virtual functions, those entries in the vtable are overwritten by the derived class constructor. This is why you should never call virtual functions from a constructor: because the vtable entries for the object may not have been set up by the derived class constructor yet, so you might end up calling base class implementations of those virtual functions&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is name mangling in C++??&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The process of encoding the parameter types with the function/method name into a unique name is called name mangling. The inverse process is called demangling.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;For example Foo::bar(int, long) const is mangled as `bar__C3Fooil&#39;.&lt;br /&gt;
For a constructor, the method name is left out. That is Foo::Foo(int, long) const is mangled as `__C3Fooil&#39;.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What happens when you make call &quot;delete this;&quot; ??&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The code has two built-in pitfalls. First, if it executes in a member function for an extern, static, or automatic object, the program will probably crash as soon as the delete statement executes. There is no portable way for an object to tell that it was instantiated on the heap, so the class cannot assert that its object is properly instantiated. Second, when an object commits suicide this way, the using program might not know about its demise. As far as the instantiating program is concerned, the object remains in scope and continues to exist even though the object did itself in. Subsequent dereferencing of the pointer can and usually does lead to disaster.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;You should never do this. Since compiler does not know whether the object was allocated on the stack or on the heap, &quot;delete this&quot; could cause a disaster.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is the difference between a pointer and a reference?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;A reference must always refer to some object and, therefore, must always be initialized; pointers do not have such restrictions. A pointer can be reassigned to point to different objects while a reference always refers to an object with which it was initialized.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;How are prefix and postfix versions of operator++() differentiated?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;The postfix version of operator++() has a dummy parameter of type int. The prefix version does not have dummy parameter.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is the difference between const char *myPointer and char *const myPointer?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Const char *myPointer is a non constant pointer to constant data; while char *const myPointer is a constant pointer to non constant data.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;How can I handle a constructor that fails?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;throw an exception. Constructors don&#39;t have a return type, so it&#39;s not possible to use return codes. The best way to signal constructor failure is therefore to throw an exception.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;How can I handle a destructor that fails?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 12pt;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Write a message to a log-file. But do not throw an exception.&lt;br /&gt;
The C++ rule is that you must never throw an exception from a destructor that is being called during the &quot;stack unwinding&quot; process of another exception. For example, if someone says throw Foo(), the stack will be unwound so all the stack frames between the throw Foo() and the } catch (Foo e) { will get popped. This is called stack unwinding.&lt;br /&gt;
During stack unwinding, all the local objects in all those stack frames are destructed. If one of those destructors throws an exception (say it throws a Bar object), the C++ runtime system is in a no-win situation: should it ignore the Bar and end up in the } catch (Foo e) { where it was originally headed? Should it ignore the Foo and look for a } catch (Bar e) { handler? There is no good answer -- either choice loses information.&lt;br /&gt;
So the C++ language guarantees that it will call terminate() at this point, and terminate() kills the process. Bang you&#39;re dead.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is Virtual Destructor?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Using virtual destructors, you can destroy objects without knowing their type - the correct destructor for the object is invoked using the virtual function mechanism. Note that destructors can also be declared as pure virtual functions for abstract classes.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;if someone will derive from your class, and if someone will say &quot;new Derived&quot;, where &quot;Derived&quot; is derived from your class, and if someone will say delete p, where the actual object&#39;s type is &quot;Derived&quot; but the pointer p&#39;s type is your class.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;
&lt;b&gt;Can you think of a situation where your program would crash without reaching the breakpoint which you set at the beginning of main()?&lt;/b&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;C++ allows for dynamic initialization of global variables before main() is invoked. It is possible that initialization of global will invoke some function. If this function crashes the crash will occur before main() is entered.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Name two cases where you MUST use initialization list as opposed to assignment in constructors.&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Both non-static const data members and reference data members cannot be assigned values; instead, you should use initialization list to initialize them.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Can you overload a function based only on whether a parameter is a value or a reference?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;No. Passing by value and by reference looks identical to the caller.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What does extern &quot;C&quot; int func(int *, Foo) accomplish?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;It will turn off &quot;name mangling&quot; for func so that one can link to code compiled by a C compiler.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;How do you access the static member of a class?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;::&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/4861472299233985465/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2012/03/c-frequently-asked-questions-3-pointer.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/4861472299233985465'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/4861472299233985465'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2012/03/c-frequently-asked-questions-3-pointer.html' title='C++ frequently asked questions (3) - Pointer and Memory management'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-7275699703967880836</id><published>2012-03-24T17:59:00.000-07:00</published><updated>2012-03-24T17:59:37.838-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview Question"/><category scheme="http://www.blogger.com/atom/ns#" term="OOP"/><title type='text'>C++ frequently asked questions (2)</title><content type='html'>&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is the diff between malloc()/free() and new/delete?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;malloc allocates memory for object in heap but doesn&#39;t invoke object&#39;s constructor to initiallize the object.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;new allocates memory and also invokes constructor to initialize the object.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;malloc() and free() do not support object semantics&lt;br /&gt;
Does not construct and destruct objects&lt;br /&gt;
string * ptr = (string *)(malloc (sizeof(string)))&lt;br /&gt;
Are not safe&lt;br /&gt;
Does not calculate the size of the objects that it construct&lt;br /&gt;
Returns a pointer to void&lt;br /&gt;
int *p = (int *) (malloc(sizeof(int)));&lt;br /&gt;
int *p = new int;&lt;br /&gt;
Are not extensible&lt;br /&gt;
new and delete can be overloaded in a class&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&quot;delete&quot; first calls the object&#39;s termination routine (i.e. its destructor) and then releases the space the object occupied on the heap memory. If an array of objects was created using new, then delete must be told that it is dealing with an array by preceding the name with an empty []:-&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Int_t *my_ints = new Int_t[10];&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;...&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;delete []my_ints;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;what is the diff between &quot;new&quot; and &quot;operator new&quot; ?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 12pt;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;
&quot;operator new&quot; works like malloc.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is difference between template and macro??&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;There is no way for the compiler to verify that the macro parameters are of compatible types. The macro is expanded without any special type checking.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;If macro parameter has a postincremented variable ( like c++ ), the increment is performed two times.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Because macros are expanded by the preprocessor, compiler error messages will refer to the expanded macro, rather than the macro definition itself. Also, the macro will show up in expanded form during debugging.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;for example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Macro:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;#define min(i, j) (i &amp;lt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 12pt;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;template:&lt;br /&gt;
template&lt;br /&gt;
T min (T i, T j)&lt;br /&gt;
{&lt;br /&gt;
return i &amp;lt;&amp;gt;&lt;br /&gt;
&lt;!--[if !supportLineBreakNewLine]--&gt;&lt;br /&gt;
&lt;!--[endif]--&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What are storage qualifiers in C++ ?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;They are..&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;const&lt;br /&gt;
volatile&lt;br /&gt;
mutable&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Const&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;keyword indicates that memory once initialized, should not be altered by a program.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;volatile&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;keyword indicates that the value in the memory location can be altered even though nothing in the program&lt;br /&gt;
code modifies the contents. for example if you have a pointer to hardware location that contains the time, where hardware changes the value of this pointer variable and not the program. The intent of this keyword to improve the optimization ability of the compiler.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;mutable&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;keyword indicates that particular member of a structure or class can be altered even if a particular structure variable, class, or class member function is constant.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;struct data&lt;br /&gt;
{&lt;br /&gt;
char name[80];&lt;br /&gt;
mutable double salary;&lt;br /&gt;
}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;const data MyStruct = { &quot;Satish Shetty&quot;, 1000 }; //initlized by complier&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 12pt;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;strcpy ( MyStruct.name, &quot;Shilpa Shetty&quot;); // compiler error&lt;br /&gt;
MyStruct.salaray = 2000 ; // complier is happy allowed&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is reference ??&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;reference is a name that acts as an alias, or alternative name, for a previously defined variable or an object.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;prepending variable with &quot;&amp;amp;&quot; symbol makes it as reference.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;for example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int a;&lt;br /&gt;
int &amp;amp;b = a;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What are C++ storage classes?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;auto&lt;br /&gt;
register&lt;br /&gt;
static&lt;br /&gt;
extern&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;auto:&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;the default. Variables are automatically created and initialized when they are defined and are destroyed at the end of the block containing their definition. They are not visible outside that block&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;register:&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;a type of auto variable. a suggestion to the compiler to use a CPU register for performance&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;static:&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;a variable that is known only in the function that contains its definition but is never destroyed and retains its value between calls to that function. It exists from the time the program begins execution&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 12pt;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;extern:&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&amp;nbsp;a static variable whose definition and placement is determined when all object and library modules are combined (linked) to form the executable code file. It can be visible outside the file where it is defined.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0.0001pt;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is passing by reference?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Method of passing arguments to a function which takes parameter of type reference.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;for example:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;void swap( int &amp;amp; x, int &amp;amp;amp;amp;amp;amp; y )&lt;br /&gt;
{&lt;br /&gt;
int temp = x;&lt;br /&gt;
x = y;&lt;br /&gt;
y = temp;&lt;br /&gt;
}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;int a=2, b=3;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;swap( a, b );&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 12pt;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Basically, inside the function there won&#39;t be any copy of the arguments &quot;x&quot; and &quot;y&quot; instead they refer to original variables a and b. so no extra memory needed to pass arguments and it is more efficient.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;When do use &quot;const&quot; reference arguments in function?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 12pt;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;a) Using const protects you against programming errors that inadvertently alter data.&lt;br /&gt;
b) Using const allows function to process both const and non-const actual arguments, while a function without const in the prototype can only accept non constant arguments.&lt;br /&gt;
c) Using a const reference allows the function to generate and use a temporary variable appropriately.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is virtual function?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;When derived class overrides the base class method by redefining the same function, then if client wants to access redefined the method from derived class through a pointer from base class object, then you must define this function in base class as virtual function.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;class parent&lt;br /&gt;
{&lt;br /&gt;
void Show()&lt;br /&gt;
{&lt;br /&gt;
cout &amp;lt;&amp;lt; &quot;i&#39;m parent&quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
};&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;class child: public parent&lt;br /&gt;
{&lt;br /&gt;
void Show()&lt;br /&gt;
{&lt;br /&gt;
cout &amp;lt;&amp;lt; &quot;i&#39;m child&quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;};&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;parent * parent_object_ptr = new child;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;parent_object_ptr-&amp;gt;show() // calls parent-&amp;gt;show() i&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;now we goto virtual world...&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;class parent&lt;br /&gt;
{&lt;br /&gt;
virtual void Show()&lt;br /&gt;
{&lt;br /&gt;
cout &amp;lt;&amp;lt; &quot;i&#39;m parent&quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
};&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;class child: public parent&lt;br /&gt;
{&lt;br /&gt;
void Show()&lt;br /&gt;
{&lt;br /&gt;
cout &amp;lt;&amp;lt; &quot;i&#39;m child&quot; &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;};&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;parent * parent_object_ptr = new child;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 12pt;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;parent_object_ptr-&amp;gt;show() // calls child-&amp;gt;show()&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;When are temporary variables created by C++ compiler?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Provided that function parameter is a &quot;const reference&quot;, compiler generates temporary variable in following 2 ways.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;a) The actual argument is the correct type, but it isn&#39;t Lvalue&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;double Cube(const double &amp;amp; num)&lt;br /&gt;
{&lt;br /&gt;
num = num * num * num;&lt;br /&gt;
return num;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;double temp = 2.0;&lt;br /&gt;
double value = cube(3.0 + temp); // argument is a expression and not a Lvalue;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;b) The actual argument is of the wrong type, but of a type that can be converted to the correct type&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 12pt;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;long temp = 3L;&lt;br /&gt;
double value = cuberoot ( temp); // long to double conversion&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is pure virtual function? or what is abstract class?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;When you define only function prototype in a base class without implementation and do the complete implementation in derived class. This base class is called abstract class and client won&#39;t able to instantiate an object using this base class.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;You can make a pure virtual function or abstract class this way..&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-left: 0.5in;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: Courier; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;class Boo&lt;br /&gt;
{&lt;br /&gt;
public:&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-left: 0.5in;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: Courier; font-size: 11.5pt; mso-bidi-font-family: Arial; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;virtual void foo() = 0;&lt;a href=&quot;&quot; name=&quot;_GoBack&quot;&gt;&lt;/a&gt;&lt;br /&gt;
}&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial;&quot;&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;Boo MyBoo; // compilation error&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/7275699703967880836/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2012/03/c-frequently-asked-questions-2.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/7275699703967880836'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/7275699703967880836'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2012/03/c-frequently-asked-questions-2.html' title='C++ frequently asked questions (2)'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-4037284945228039342</id><published>2012-03-24T17:57:00.000-07:00</published><updated>2012-03-24T17:57:09.753-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview Question"/><category scheme="http://www.blogger.com/atom/ns#" term="OOP"/><title type='text'>C++ frequently asked questions (1)</title><content type='html'>&lt;div class=&quot;MsoNormal&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; margin-bottom: 12pt;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;What is inheritance?&lt;/span&gt;&lt;/b&gt;&lt;span style=&quot;color: #333333; font-family: &amp;quot;Arial&amp;quot;,&amp;quot;sans-serif&amp;quot;; font-size: 11.5pt; mso-fareast-font-family: &amp;quot;Times New Roman&amp;quot;;&quot;&gt;&lt;br /&gt;
Inheritance allows one class to reuse the state and behavior of another class. The derived class inherits the properties and method implementations of the base class and extends it by overriding methods and adding additional properties and methods.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What is encapsulation??&lt;/b&gt;&lt;br /&gt;
Containing and hiding information about an object, such as internal data structures and code. Encapsulation isolates the internal complexity of an object&#39;s operation from the rest of the application. For example, a client component asking for net revenue from a business object need not know the data&#39;s origin.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What is Polymorphism??&lt;br /&gt;
&lt;/b&gt;Polymorphism allows a client to treat different objects in the same way even if they were created from different classes and exhibit different behaviors.&lt;br /&gt;
You can use implementation inheritance to achieve polymorphism in languages such as C++ and Java.&lt;br /&gt;
Base class object&#39;s pointer can invoke methods in derived class objects.&lt;br /&gt;
You can also achieve polymorphism in C++ by function overloading and operator overloading.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What is assignment operator?&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
Default assignment operator handles assigning one object to another of the same class. Member to member copy (shallow copy)&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What are all the implicit member functions of the class? Or what are all the functions which compiler implements for us if we don&#39;t define one.??&lt;/b&gt;&lt;br /&gt;
default ctor(Constructor)&lt;br /&gt;
copy ctor&lt;br /&gt;
assignment operator&lt;br /&gt;
default destructor&lt;br /&gt;
address operator&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What is constructor or ctor?&lt;br /&gt;
&lt;/b&gt;Constructor creates an object and initializes it. It also creates vtable for virtual functions. It is different from other methods in a class.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What is default constructor?&lt;/b&gt;&lt;br /&gt;
Constructor with no arguments or all the arguments has default values.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What is copy constructor?&lt;/b&gt;&lt;br /&gt;
Constructor which initializes the it&#39;s object member variables ( by shallow copying) with another object of the same class. If you don&#39;t implement one in your class then compiler implements one for you.&lt;br /&gt;
for example:&lt;br /&gt;
Boo Obj1(10); // calling Boo constructor&lt;br /&gt;
Boo Obj2(Obj1); // calling boo copy constructor&lt;br /&gt;
Boo Obj2 = Obj1;// calling boo copy constructor&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;When are copy constructors called?&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
Copy constructors are called in following cases:&lt;br /&gt;
a) when a function returns an object of that class by value&lt;br /&gt;
b) when the object of that class is passed by value as an argument to a function&lt;br /&gt;
c) when you construct an object based on another object of the same class&lt;br /&gt;
d) When compiler generates a temporary object&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What is conversion constructor?&lt;/b&gt;&lt;br /&gt;
constructor with a single argument makes that constructor as conversion ctor and it can be used for type conversion.&lt;br /&gt;
for example:&lt;br /&gt;
class Boo&lt;br /&gt;
{&lt;br /&gt;
public:&lt;br /&gt;
Boo( int i );&lt;br /&gt;
};&lt;br /&gt;
Boo BooObject = 10 ; // assigning int 10 Boo object&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What is destructor?&lt;/b&gt;&lt;br /&gt;
Destructor usually deletes any extra resources allocated by the object.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What is conversion operator??&lt;/b&gt;&lt;br /&gt;
class can have a public method for specific data type conversions.&lt;br /&gt;
for example:&lt;br /&gt;
class Boo&lt;br /&gt;
{&lt;br /&gt;
double value;&lt;br /&gt;
public:&lt;br /&gt;
Boo(int i )&lt;br /&gt;
operator double()&lt;br /&gt;
{&lt;br /&gt;
return value;&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
Boo BooObject;&lt;br /&gt;
double i = BooObject; // assigning object to variable i of type double. now conversion operator gets called to assign the value.&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/4037284945228039342/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2012/03/c-frequently-asked-questions-1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/4037284945228039342'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/4037284945228039342'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2012/03/c-frequently-asked-questions-1.html' title='C++ frequently asked questions (1)'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-517386314159597252</id><published>2012-03-24T17:53:00.000-07:00</published><updated>2012-03-24T17:53:14.873-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Perl"/><category scheme="http://www.blogger.com/atom/ns#" term="PID"/><category scheme="http://www.blogger.com/atom/ns#" term="Shell"/><category scheme="http://www.blogger.com/atom/ns#" term="Unix"/><title type='text'>Check elapsed time</title><content type='html'>check elapsed time&lt;br /&gt;
&lt;br /&gt;
Here I collected several ways to check elapsed time of agiven PID, when you didn’t have time or date added to the command line&lt;br /&gt;
&lt;br /&gt;
1) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ps –oetimePID&lt;br /&gt;
&lt;br /&gt;
2) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ps –p PID–o etime=&lt;br /&gt;
&lt;br /&gt;
3) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;check thetime when the output file is updated&lt;br /&gt;
&lt;br /&gt;
This could be used to check the elapsed time even if the jobis done, as long as you have a start time&lt;br /&gt;
&lt;br /&gt;
4) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ps -eopid, etime, args&lt;br /&gt;
&lt;br /&gt;
5) &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A shellscript with a bit of perl (should work on all variants of UNIX)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
#!/bin/ksh&lt;br /&gt;
&lt;br /&gt;
#puptime.ksh - Gavin Satur - http://cybergav.in/2009/11/09/puptime&lt;br /&gt;
&lt;br /&gt;
#Simple script to calculate the uptime (elapsed wall clock time) of a process&lt;br /&gt;
&lt;br /&gt;
##############################################################################&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
#Accept PID and do some basic validation&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
proc_pid=$1&lt;br /&gt;
&lt;br /&gt;
if [ -z &quot;$proc_pid&quot; ]; then&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;print &quot;\nERROR : Missing inputargument. SYNTAX: ksh puptime.ksh &amp;lt;pid&amp;gt;\n&quot;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;exit 999&lt;br /&gt;
&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
if [ ! -d /proc/$proc_pid ]; then&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;print &quot;\nERROR : No directory forPID $proc_pidin /proc. Check if process is running!\n&quot;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;nbsp;exit 999&lt;br /&gt;
&lt;br /&gt;
fi&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
#Calculate start time of process and current time in epoch time using a bit ofperl&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
proc_stime=`perl -e &#39;use File::stat; &amp;nbsp;my $filename= &quot;$ARGV[0]&quot;; $sb = stat($filename); printf &quot;%s&quot;,$sb-&amp;gt;mtime;&#39; /proc/$proc_pid`&lt;br /&gt;
&lt;br /&gt;
currtime=`perl -e &#39;print time;&#39;`&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
#Calculate process uptime in seconds and then slice&#39;n&#39;dice for human-friendlyoutput&lt;br /&gt;
&lt;br /&gt;
#&lt;br /&gt;
&lt;br /&gt;
proc_time=$(( currtime - proc_stime ))&lt;br /&gt;
&lt;br /&gt;
proc_time_days=$(( proc_time / 86400 ))&lt;br /&gt;
&lt;br /&gt;
proc_time_secs=$(( proc_time % 86400 ))&lt;br /&gt;
&lt;br /&gt;
proc_time_hours=$(( proc_time_secs / 3600 ))&lt;br /&gt;
&lt;br /&gt;
proc_time_secs=$(( proc_time_secs % 3600 ))&lt;br /&gt;
&lt;br /&gt;
proc_time_minutes=$((proc_time_secs / 60 ))&lt;br /&gt;
&lt;br /&gt;
proc_time_secs=$(( proc_time_secs % 60 ))&lt;br /&gt;
&lt;br /&gt;
print&quot;\nUPTIME FOR PROCESS WITH PID $proc_pid = $proc_time_days day(s) $proc_time_hours hour(s) $proc_time_minutes minute(s) $proc_time_secs second(s) \n&quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here we recommend 1) and 4) . It prints out the elapsed time(the “e” in etime) in POSIX format. The output format is like this:&lt;br /&gt;
&lt;br /&gt;
5059 7-13:09:53 /bin/zsh /usr/bin/grml-x fluxbox&lt;br /&gt;
&lt;br /&gt;
…which of course means: PID 5059, elapsed time 7 days, 13hours,09 minutes, 53 seconds.&lt;br /&gt;
&lt;br /&gt;
This is the time I started this cute little window managerfrom the shell.&lt;br /&gt;
&lt;br /&gt;
The ps parameters used are :&lt;br /&gt;
&lt;br /&gt;
-e lists information about evey process running&lt;br /&gt;
&lt;br /&gt;
-o prints information according to the format specified&lt;br /&gt;
&lt;br /&gt;
…so saying “I want the pid, the elapsed time, and all therest of the info” gives you the result up above.&lt;br /&gt;
&lt;br /&gt;
There is also an option stime for -o , but this only returnsthe starting day.&lt;br /&gt;
&lt;br /&gt;
techero@barrioverde ~ % ps -eo pid,stime,args|grep 5059&lt;br /&gt;
&lt;br /&gt;
5059 Feb07 /bin/zsh /usr/bin/grml-x fluxbox</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/517386314159597252/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2012/03/check-elapsed-time.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/517386314159597252'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/517386314159597252'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2012/03/check-elapsed-time.html' title='Check elapsed time'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-1907614055626611361</id><published>2011-09-19T12:43:00.000-07:00</published><updated>2011-09-19T12:43:17.481-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C"/><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="C++ questions"/><title type='text'>Difference between c and c++</title><content type='html'>&lt;h2 class=&quot;title icon&quot;&gt;Difference between c and c++     &lt;/h2&gt;&lt;div class=&quot;content hasad&quot;&gt;      &lt;div id=&quot;post_message_36891&quot;&gt;       &lt;blockquote class=&quot;postcontent restore &quot;&gt;        1. C does not have any classes or objects. It is procedure and  function driven. There is no concept of access through objects and  structures are the only place where there is a access through a  compacted variable. c++ is object oriented.&lt;br /&gt;
&lt;br /&gt;
2. C structures have a diferent behaviour compared to c++ structures. Structures in c do not accept functions as their parts.&lt;br /&gt;
&lt;br /&gt;
3. C input/output is based on library and the prcesses are carried out  by including functions. C++ i/o is made through console commands cin and  cout.&lt;br /&gt;
&lt;br /&gt;
4. C functions do not support overloading. Operator overloading is a  process in which the same function has two or more different behaviours  based on the data input by the user.&lt;br /&gt;
&lt;br /&gt;
5. C does not support new or delete commands. The memory operations to  free or alllocate memory in c are carried out by malloc() and free().&lt;br /&gt;
&lt;br /&gt;
6. Undeclared functions in c++ are not allowed. The function has to have  a prototype defined before the main() before use in c++ although in c  the functions can be declared at the point of use.&lt;br /&gt;
&lt;br /&gt;
7. After declaring structures and enumerators in c we cannot declare the  variable for the structure right after the end of the structure as in  c++.&lt;br /&gt;
&lt;br /&gt;
8. For an int main() in c++ we may not write a return statement but the return is mandatory in c if we are using int main().&lt;br /&gt;
&lt;br /&gt;
9. In C++ identifiers are not allowed to contain two or more consecutive  underscores in any position. C identifiers cannot start with two or  more consecutive underscores, but may contain them in other positions.&lt;br /&gt;
&lt;br /&gt;
10. C has a top down approch whereas c++ has a bottom up approach.&lt;br /&gt;
&lt;br /&gt;
11.  in c a character constant is automatically elevated to and integer whereas in c++ this is not the case.&lt;br /&gt;
&lt;br /&gt;
12. In c declaring the global variable several times is allowed but this is not allowed in c++.&lt;/blockquote&gt;&lt;br /&gt;
Source: &lt;a href=&quot;http://forum.codecall.net/c-tutorials/7041-difference-between-c-c.html&quot;&gt;here&lt;/a&gt;. &lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/1907614055626611361/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2011/09/difference-between-c-and-c.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/1907614055626611361'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/1907614055626611361'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2011/09/difference-between-c-and-c.html' title='Difference between c and c++'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-7013052364849032048</id><published>2011-09-09T19:52:00.000-07:00</published><updated>2011-09-09T19:52:18.682-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Data Structure; Interview Question"/><category scheme="http://www.blogger.com/atom/ns#" term="Tutorial"/><title type='text'>Source for Data Structure Interviews</title><content type='html'>&lt;ul&gt;&lt;li&gt;&lt;a class=&quot;external text&quot; href=&quot;http://academicearth.org/courses/data-structures&quot; rel=&quot;nofollow&quot;&gt;UC Berkeley video course on data structures&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;h3&gt;&lt;a dir=&quot;ltr&quot; href=&quot;http://www.youtube.com/watch?v=QMV45tHCYNI&quot; title=&quot;CS 61B Lecture 1 - Course Overview&quot;&gt;CS 61B Lecture 1 - Course Overview&lt;/a&gt;&lt;/h3&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&quot;external text&quot; href=&quot;http://www.cse.unr.edu/%7Ebebis/CS308/&quot; rel=&quot;nofollow&quot;&gt;CSE.unr.edu&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;&lt;a class=&quot;external text&quot; href=&quot;http://www.cs.auckland.ac.nz/software/AlgAnim/ds_ToC.html&quot; rel=&quot;nofollow&quot;&gt;Data structures course with animations&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class=&quot;external text&quot; href=&quot;http://courses.cs.vt.edu/%7Ecsonline/DataStructures/Lessons/index.html&quot; rel=&quot;nofollow&quot;&gt;Data structure tutorials with animations&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/7013052364849032048/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2011/09/source-for-data-structure-interviews.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/7013052364849032048'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/7013052364849032048'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2011/09/source-for-data-structure-interviews.html' title='Source for Data Structure Interviews'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-8660423683271875867</id><published>2011-08-21T10:59:00.000-07:00</published><updated>2011-08-21T10:59:55.516-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><category scheme="http://www.blogger.com/atom/ns#" term="Investment Banks"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Top 20 Core Java Interview Questions for Investment Banks</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;background-color: white; color: black; text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 24px; font-weight: bold;&quot;&gt;&lt;u&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;Top 20 Core Java &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD7&quot;&gt;Interview&lt;/span&gt; questions in Finance domain&lt;/span&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;This is a new series of sharing &lt;i&gt;core Java interview question on Finance domain &lt;/i&gt;and mostly on Big&lt;i&gt;&lt;b&gt; Investment bank&lt;/b&gt;&lt;/i&gt;. Anybody who is preparing for any &lt;i&gt;&lt;b&gt;&lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD5&quot;&gt;Java developer&lt;/span&gt; Interview on any &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD6&quot;&gt;Investment&lt;/span&gt; bank &lt;/b&gt;&lt;/i&gt;can be benefited from these set of core Java Interview questions. I have collected these questions from my friends and I thought &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD8&quot;&gt;to share&lt;/span&gt; with you all.&amp;nbsp; I hope &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD4&quot;&gt;this will&lt;/span&gt; be helpful for both of us. Please share answers for unanswered question and let us know how good these interview questions are.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;Recently I was looking at comments made on java interview questions given in this post and I found some of them quite useful to include into main post to benefit all.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;1. What is immutable object? Can you write immutable object?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;You  need to make class final and all its member final so that once objects  gets crated no one can modify its state. You can achieve same  functionality by making member as non final but private and not  modifying them except in constructor.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;2. Does all property of immutable object needs to be final?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;Not  necessary as stated above you can achieve same functionality by making  member as non final but private and not modifying them except in  constructor.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;3. What is the difference between creating String as new () and literal?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;When  we create string with new () it’s created in heap and not added into  string pool while String created using literal are created in String  pool itself which exists in Perm area of heap.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;,Verdana,Arial,sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;String s = new String(&quot;Test&quot;);&lt;br /&gt;
&lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD10&quot;&gt;will put&lt;/span&gt; the object in String  pool , it it does then why do one need String.intern() method which is  used to put Strings into String pool explicitly. its only when you  create String object as String literal e.g. String s = &quot;Test&quot; it put the  String in pool.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;4. How does substring () inside String works?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;Another  good question, I think answer is not sufficient but here it is  “Substring creates new object out of string by taking a portion of  original string”.&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;suggested by Anand and Anonymous&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;,Verdana,Arial,sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;The  substring() method is used to return a part (or substring) of the  String used to invoke the method. The first argument represents the  starting location (zero-based) of the substring. If the call has only  one argument, the substring returned will include the characters to the  end of the original String. If the call has two arguments, the substring  returned will end with the character located in the nth position of the  original String where n is the second argument. Unfortunately, the  ending argument is not zero-based, so if the second argument is 7, the  last character in the returned String will be in the original String’s 7  position, which is index 6. Let’s look at an example:&lt;br /&gt;
String x = &quot;0123456789&quot;;&lt;br /&gt;
&lt;br /&gt;
System.out.println( x.substring(5) ); // output is &quot;56789&quot;&lt;br /&gt;
System.out.println( x.substring(5, 8)); // output is &quot;567&quot;&lt;br /&gt;
&lt;br /&gt;
The first example should be easy: start at index 5 and return the rest  of the String. The second example should be read as follows: start at  index 5 and return the characters up to and including the 8th position  (index 7).&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;,Verdana,Arial,sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;,Verdana,Arial,sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&lt;b&gt;and @Anonymous pointed out some interesting fact:&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;,Verdana,Arial,sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;omething important about String.substring() method, its implementation calls the following String(...) constructor :&lt;br /&gt;
&lt;br /&gt;
// Package private constructor which &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD9&quot;&gt;shares&lt;/span&gt; value array for speed.&lt;br /&gt;
String(int offset, int count, char value[]) {&lt;br /&gt;
this.value = value;&lt;br /&gt;
this.offset = offset;&lt;br /&gt;
this.count = count;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
That means the new String() object returned by substring(...) shares the same backing array (this.value) as the original string object.&lt;br /&gt;
&lt;br /&gt;
Thus if your original string object is 1GB long, the substring object will always be 1GB long too!&lt;br /&gt;
&lt;br /&gt;
You will probably want to trim the new array size to the substring range, this should do the job:&lt;br /&gt;
&lt;br /&gt;
String veryLongString = readFromFile(file);&lt;br /&gt;
String tinyString = new String(veryLongString.substring(1,10));&lt;br /&gt;
&lt;br /&gt;
The String(String) constructor is implemented that way:&lt;br /&gt;
&lt;br /&gt;
public String(String original) {&lt;br /&gt;
...&lt;br /&gt;
if (originalValue.length &amp;gt; size) {&lt;br /&gt;
// The array representing the String is bigger than the new&lt;br /&gt;
// String itself. Perhaps this constructor is being called&lt;br /&gt;
// in order to trim the baggage, so make a copy of the array.&lt;br /&gt;
int off = original.offset;&lt;br /&gt;
v = Arrays.copyOfRange(originalValue, off, off+size);&lt;br /&gt;
}&lt;br /&gt;
...&lt;br /&gt;
}&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;5. Which two method you need to implement for key in hashMap ? &lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;(equals and hashcode) read &lt;a href=&quot;http://javarevisited.blogspot.com/2011/02/how-hashmap-works-in-java.html&quot;&gt;How HashMap works in Java&lt;/a&gt; for detailed explanation.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;6. Where does these &amp;nbsp;two method comes in picture during get operation?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;See here&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;a href=&quot;http://javarevisited.blogspot.com/2011/02/how-hashmap-works-in-java.html&quot;&gt;How HashMap works in Java&lt;/a&gt; for detailed explanation.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;7. How do you handle error condition while writing stored procedure or accessing stored procedure from java?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;Open for all, my friend didn&#39;t know the answer so he didn&#39;t mind telling me.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;8. &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD11&quot;&gt;What is difference&lt;/span&gt; between &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD12&quot;&gt;Executor&lt;/span&gt;.submit() and Executer.execute() method ? &lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;(Former returns an object of Future which can be used to find result from worker thread)&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;b&gt;@vinit Saini &lt;/b&gt;suggesed a very good point related to this core java interview question&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;,Verdana,Arial,sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;There  is a difference when looking at exception handling. If your tasks  throws an exception and if it was submitted with execute this exception  will go to the uncaught exception handler (when you don&#39;t have provided  one explicitly, the default one will just print the stack trace to  System.err). If you submitted the task with submit any thrown exception,  checked or not, is then part of the task&#39;s return status. For a task  that was submitted with submit and that terminates with an exception,  the Future.get will rethrow this exception, wrapped in an  ExecutionException.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;9. What is the difference between factory and abstract factory pattern?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;Open  for all, he explains about factory pattern and how factory pattern saves  maintenance time by encapsulating logic of object creation but didn&#39;t  know exact answer&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;@Raj suggested&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;,Verdana,Arial,sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Abstract  Factory provides one more level of abstraction. Consider different  factories each extended from an Abstract Factory and responsible for  creation of different hierarchies of objects based on the type of  factory. E.g. AbstractFactory extended by AutomobileFactory,  UserFactory, RoleFactory etc. Each individual factory would be  responsible for creation of objects in that genre.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;10. What is Singleton? is it better to make whole method synchronized or only critical section synchronized ?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;see my article &lt;a href=&quot;http://javarevisited.blogspot.com/2011/03/10-interview-questions-on-singleton.html&quot;&gt;10 Interview questions on Singleton Pattern in Java&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;11. Can you write Critical section code for singleton?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;check here&amp;nbsp;&lt;/span&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt; &lt;a href=&quot;http://javarevisited.blogspot.com/2011/03/10-interview-questions-on-singleton.html&quot;&gt;10 Interview questions on Singleton Pattern in Java&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;12. Can you write code for iterating over hashmap in Java 4 and Java 5 ?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;/div&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;Tricky one but he managed to write using while and &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD3&quot;&gt;for loop&lt;/span&gt;.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;13. When do you override hashcode and equals() ?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;Whenever  necessary especially if you want to do equality check or want to use  your object as key in HashMap. check this for writing equals method  correctly &lt;a href=&quot;http://javarevisited.blogspot.com/2011/02/how-to-write-equals-method-in-java.html&quot;&gt;5 tips on equals in Java&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;14. What will be the problem if you don&#39;t override hashcode() method ?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;You will not be able to recover your object from hash Map if that is used as key in HashMap. &lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;See here&amp;nbsp; &lt;/span&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;a href=&quot;http://javarevisited.blogspot.com/2011/02/how-hashmap-works-in-java.html&quot;&gt;How HashMap works in Java&lt;/a&gt; for detailed explanation.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;15. Is it better to synchronize critical section of getInstance() method or whole getInstance() method ?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;Answer is critical section because if we lock whole method than every time some one call &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD2&quot;&gt;this method&lt;/span&gt; will have to wait even though we are not creating any object)&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;16. What is the difference when String is gets created using literal or new() operator ?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;When  we create string with new() its created in heap and not added into  string pool while String created using literal are created in String  pool itself which exists in Perm area of heap.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;17. Does not overriding hashcode() method has any performance implication ?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;This is a good question and open to all , as per my knowledge a poor hashcode function will result in frequent &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD1&quot;&gt;collision&lt;/span&gt; in HashMap which eventually increase time for adding an object into Hash Map.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;18. What’s wrong using HashMap in multithreaded environment? When get() method go to infinite loop ?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;Another good question. His answer was during concurrent access and&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 11px;&quot;&gt;re-sizing&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: xx-small;&quot;&gt;.&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;span style=&quot;font-family: Verdana; font-size: 8pt;&quot;&gt;19.&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;,Verdana,Arial,sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Give a simplest way to find out the time a method takes for execution without using any profiling tool?&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;,Verdana,Arial,sans-serif; font-size: xx-small;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;line-height: 18px;&quot;&gt;this questions is suggested by&lt;b&gt; @Mohit&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;,Verdana,Arial,sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Read  the system time just before the method is invoked and immediately after  method returns. Take the time difference, which will give you the time  taken by a method for execution.&lt;br /&gt;
&lt;br /&gt;
To put it in code…&lt;br /&gt;
&lt;br /&gt;
long start = System.currentTimeMillis ();&lt;br /&gt;
method ();&lt;br /&gt;
long end = System.currentTimeMillis ();&lt;br /&gt;
&lt;br /&gt;
System.out.println (“Time taken for execution is ” + (end – start));&lt;br /&gt;
&lt;br /&gt;
Remember that if the time taken for execution is too small, it might  show that it is taking zero milliseconds for execution. Try it on a  method which is big enough, in the sense the one which is doing  considerable amout of processing&lt;/span&gt;&lt;/div&gt;&lt;div dir=&quot;ltr&quot; style=&quot;background-color: white; color: black; text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;,Verdana,Arial,sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div dir=&quot;ltr&quot; style=&quot;background-color: white; color: black; text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;,Verdana,Arial,sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;Source: &lt;a href=&quot;http://javarevisited.blogspot.com/2011/04/top-20-core-java-interview-questions.html&quot;&gt;here &lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div dir=&quot;ltr&quot; style=&quot;background-color: white; color: black; text-align: left;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Trebuchet MS&#39;,Verdana,Arial,sans-serif; font-size: 13px; line-height: 18px;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/8660423683271875867/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2011/08/top-20-core-java-interview-questions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/8660423683271875867'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/8660423683271875867'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2011/08/top-20-core-java-interview-questions.html' title='Top 20 Core Java Interview Questions for Investment Banks'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-4332233097887428390</id><published>2011-08-21T10:55:00.000-07:00</published><updated>2011-08-21T10:55:04.923-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++ questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Facebook"/><category scheme="http://www.blogger.com/atom/ns#" term="interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Mircosoft"/><title type='text'>Facebook /Mircosoft interview question - Analysis + several solutions in C++/Java</title><content type='html'>Given an array A, output another array B such that B[k] is the product of all elements in A but A[k]. Division is not allowed, More specifically,&lt;br /&gt;
&lt;br /&gt;
&lt;blockquote&gt;   Given an array of numbers, &lt;code&gt;nums&lt;/code&gt;, return an array of numbers &lt;code&gt;products&lt;/code&gt;, where &lt;code&gt;products[i]&lt;/code&gt; is the product of all &lt;code&gt;nums[j], j != i&lt;/code&gt;.&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;Input : [1, 2, 3, 4, 5]
Output: [(2*3*4*5), (1*3*4*5), (1*2*4*5), (1*2*3*5), (1*2*3*4)]
      = [120, 60, 40, 30, 24]
&lt;/code&gt;&lt;/pre&gt;You must do this in &lt;code&gt;O(N)&lt;/code&gt; without using division.&lt;/blockquote&gt;&lt;br /&gt;
Full analysis:&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;votecell&quot;&gt;&lt;div class=&quot;vote&quot;&gt;     &lt;span class=&quot;vote-count-post&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;span class=&quot;vote-accepted-on&quot; title=&quot;The question owner accepted this as the best answer Apr 24 &#39;10 at 16:30&quot;&gt;&lt;/span&gt; &lt;/div&gt;&lt;/td&gt;   &lt;td class=&quot;answercell&quot;&gt;     &lt;div class=&quot;post-text&quot;&gt;An explanation of the method is: The trick is to construct the arrays (in the case for 4 elements)&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;{              1,         a[0],    a[0]*a[1],    a[0]*a[1]*a[2],  }
{ a[1]*a[2]*a[3],    a[2]*a[3],         a[3],                 1,  }
&lt;/code&gt;&lt;/pre&gt;Both of which can be done in O(n) by starting at the left and right edges respectively.&lt;br /&gt;
Then multiplying the two arrays element by element gives the required result&lt;br /&gt;
My code would look something like this:&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;int a[N] // This is the input
int products_below[N];
p=1;
for(int i=0;i&amp;lt;N;++i)
{
  products_below[i]=p;
  p*=a[i];
}

int products_above[N];
p=1;
for(int i=N-1;i&amp;gt;=0;--i)
{
  products_above[i]=p;
  p*=a[i];
}

int products[N]; // This is the result
for(int i=0;i&amp;lt;N;++i)
{
  products[i]=products_below[i]*products_above[i];
}
&lt;/code&gt;&lt;/pre&gt;If you need to be O(1) in space too you can do this (which is less clear IMHO)&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;int a[N] // This is the input
int products[N];

// Get the products below the curent index
p=1;
for(int i=0;i&amp;lt;N;++i)
{
  products[i]=p;
  p*=a[i];
}

// Get the products above the curent index
p=1;
for(int i=N-1;i&amp;gt;=0;--i)
{
  products[i]*=p;
  p*=a[i];
}&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;div class=&quot;post-text&quot;&gt;Here is a small recursive function in C++ to  do the modification in place. It requires O(n) extra space (on stack)  though. Assuming the array is in a and N holds the array length, we have&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;int multiply(int *a, int fwdProduct, int indx) {
    int revProduct = 1;
    if (indx &amp;lt; N) {
       revProduct = multiply(a, fwdProduct*a[indx], indx+1);
       int cur = a[indx];
       a[indx] = fwdProduct * revProduct;
       revProduct *= cur;
    }
    return revProduct;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;pre&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;//Here is a small recursive function in &lt;code&gt;Java&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code&gt;static int multiply(int[] nums, int p, int n) {
    return (n == nums.length) ? 1
      : nums[n] * (p = multiply(nums, nums[n] * (nums[n] = p), n + 1))
          + 0*(nums[n] *= p);
}

int[] arr = {1,2,3,4,5};
multiply(arr, 1, 0);
System.out.println(Arrays.toString(arr));
// prints &quot;[120, 60, 40, 30, 24]&quot;&lt;/code&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;Here&#39;s another method to solve it in Java. Apologies for the non-standard  formatting, but the code has a lot of duplication, and this is the best  I can do to make it readable.&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;code&gt;import java.util.Arrays;

public class Products {
    static int[] products(int... nums) {
        final int N = nums.length;
        int[] prods = new int[N];
        Arrays.fill(prods, 1);
        for (int
           i = 0, pi = 1    ,  j = N-1, pj = 1  ;
           (i &amp;lt; N)         &amp;amp;&amp;amp; (j &amp;gt;= 0)          ;
           pi *= nums[i++]  ,  pj *= nums[j--]  )
        {
           prods[i] *= pi   ;  prods[j] *= pj   ;
        }
        return prods;
    }
    public static void main(String[] args) {
        System.out.println(
            Arrays.toString(products(1, 2, 3, 4, 5))
        ); // prints &quot;[120, 60, 40, 30, 24]&quot;
    }
}&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code&gt;&amp;nbsp;&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code&gt;//Source: &lt;a href=&quot;http://stackoverflow.com/questions/2680548/interview-q-given-an-array-of-numbers-return-array-of-products-of-all-other-num&quot;&gt;here &lt;/a&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre&gt;&lt;code&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/4332233097887428390/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2011/08/facebook-mircosoft-interview-question.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/4332233097887428390'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/4332233097887428390'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2011/08/facebook-mircosoft-interview-question.html' title='Facebook /Mircosoft interview question - Analysis + several solutions in C++/Java'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-2050034179051786522</id><published>2011-08-17T20:10:00.000-07:00</published><updated>2011-08-17T20:11:27.766-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++ questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Hashtable"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview Question"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><category scheme="http://www.blogger.com/atom/ns#" term="Map"/><category scheme="http://www.blogger.com/atom/ns#" term="Morgan Stanley"/><title type='text'>Morgan Stanley Interview Question</title><content type='html'>&lt;br /&gt;
&lt;div class=&quot;questionHeader&quot;&gt;&lt;div class=&quot;questionTitle&quot;&gt;&lt;a href=&quot;http://www.careercup.com/question?id=6175809&quot;&gt; 			&lt;b&gt; 				Morgan Stanley 			&lt;/b&gt; 			Interview Question: 2010&lt;b&gt;&lt;/b&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;questionBody&quot;&gt;Suppose you have a large file with lots of words. How would you find the unique words and their count?&lt;br /&gt;
What kind of data structure u will use? What will be the time complexity and space complexity?&lt;br /&gt;
&lt;br /&gt;
/* Algorithm to count words in a file. Please dont reply opinions on the code, comments on complexity analysis is appreciated&lt;br /&gt;
For each word check if the word exists in the hash, if it doesnt then insert the word with a count 1&lt;br /&gt;
if it does then increment the value&lt;br /&gt;
For each word in the hashmap, print word and its count&lt;br /&gt;
Complexity: Linear insertion and space&lt;br /&gt;
NOTE:The code only compiles with newer C++ use the switch -std=c++0x in your Makefile*/&lt;br /&gt;
#include &amp;lt;iostream&amp;gt; &lt;br /&gt;
#include &amp;lt;vector&amp;gt;&lt;br /&gt;
#include &amp;lt;unordered_map&amp;gt;&lt;br /&gt;
typedef std::unordered_map&amp;lt;std::string, int&amp;gt; MyHashMap;&lt;br /&gt;
void printMyHashMap(MyHashMap::const_iterator itr,MyHashMap::const_iterator enditr){&lt;br /&gt;
while(itr!=enditr){&lt;br /&gt;
std::cout&amp;lt;&amp;lt;(*itr).first&amp;lt;&amp;lt;&quot; : &quot;&amp;lt;&amp;lt;(*itr).second&amp;lt;&amp;lt;std::endl;&lt;br /&gt;
++itr;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
int main(){ &lt;br /&gt;
MyHashMap wordsMap; //declare unordered map&lt;br /&gt;
//vector of strings&lt;br /&gt;
std::vector&amp;lt;std::string&amp;gt; strings {&quot;count&quot;,&quot;words&quot;,&quot;in&quot;,&quot;a&quot;,&quot;file&quot;,&lt;br /&gt;
&quot;and&quot;,&quot;print&quot;,&quot;words&quot;,&quot;with&quot;,&quot;their&quot;,&quot;count&quot;,&lt;br /&gt;
&quot;.&quot;,&quot;more&quot;,&quot;words&quot;,&quot;file&quot;};&lt;br /&gt;
int len = strings.size();&lt;br /&gt;
std::vector&amp;lt;std::string&amp;gt;::const_iterator wordsItr;&lt;br /&gt;
wordsItr = strings.begin();&lt;br /&gt;
MyHashMap::iterator mapItr = wordsMap.begin();&lt;br /&gt;
for ( wordsItr=strings.begin(); wordsItr!=strings.end(); wordsItr++ ){&lt;br /&gt;
mapItr = wordsMap.find(*wordsItr);&lt;br /&gt;
if(mapItr==wordsMap.end()){	//if word not found then &lt;br /&gt;
wordsMap.insert(MyHashMap::value_type(*wordsItr, 1));&lt;br /&gt;
}else{&lt;br /&gt;
(*mapItr).second = ++(*mapItr).second;		}&lt;br /&gt;
}&lt;br /&gt;
std::cout&amp;lt;&amp;lt;&quot;words and their count :&quot;&amp;lt;&amp;lt;std::endl;&lt;br /&gt;
printMyHashMap(wordsMap.begin(),wordsMap.end());&lt;br /&gt;
return (0);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
///2&lt;br /&gt;
&lt;div class=&quot;commentBody&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;algorithm&amp;gt;&lt;br /&gt;
#include &amp;lt;vector&amp;gt;&lt;br /&gt;
#include &amp;lt;fstream&amp;gt;&lt;br /&gt;
#include &amp;lt;map&amp;gt;&lt;br /&gt;
#include &amp;lt;iterator&amp;gt;&lt;br /&gt;
using namespace std;&lt;br /&gt;
int main() {&lt;br /&gt;
string str;&lt;br /&gt;
ifstream in(&quot;input.txt&quot;);&lt;br /&gt;
map&amp;lt;string, int&amp;gt; m;&lt;br /&gt;
if (in.is_open()) {&lt;br /&gt;
while(in &amp;gt;&amp;gt; str) {&lt;br /&gt;
m[str]++;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
for(map&amp;lt;string, int&amp;gt;::iterator it = m.begin(); it != m.end(); it++) {&lt;br /&gt;
cout &amp;lt;&amp;lt; (*it).first &amp;lt;&amp;lt;&quot;\t&quot; &amp;lt;&amp;lt; (*it).second &amp;lt;&amp;lt; endl;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
input.txt&lt;br /&gt;
abc abc abc abc abc abc abc abcdef abc abcd&lt;br /&gt;
abc abc abc abc abc abc abc abcdef abc abcd&lt;br /&gt;
abc abc abc abc abc abc abc abcdef abc abcd&lt;br /&gt;
abc abc abc abc abc abc abc abcdef abc abcd&lt;br /&gt;
count words in a file and print words with their count more words file&lt;br /&gt;
output&lt;br /&gt;
ajay@ubuntu:~/workspace$ ./a.out &lt;br /&gt;
a	1&lt;br /&gt;
abc	32&lt;br /&gt;
abcd	4&lt;br /&gt;
abcdef	4&lt;br /&gt;
and	1&lt;br /&gt;
count	2&lt;br /&gt;
file	2&lt;br /&gt;
in	1&lt;br /&gt;
more	1&lt;br /&gt;
print	1&lt;br /&gt;
their	1&lt;br /&gt;
with	1&lt;br /&gt;
words	3&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
//Java method&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
import java.util.HashMap;&lt;br /&gt;
public class TestTest {&lt;br /&gt;
public static void main(String[] args){&lt;br /&gt;
String inputString = &quot;abc abc abc abc abc abc abc abcdef abc abcd abc abc abc abc abc abc abc abcdef abc abcd&quot; +&lt;br /&gt;
&quot; abc abc abc abc abc abc abc abcdef abc abcd abc abc abc abc abc abc abc abcdef abc abcd&quot; +&lt;br /&gt;
&quot; count words in a file and print words with their count more words file&quot;;&lt;br /&gt;
HashMap&amp;lt;Object, Integer&amp;gt; myMap = new HashMap&amp;lt;Object, Integer&amp;gt;(){&lt;br /&gt;
@Override&lt;br /&gt;
public Integer put(Object arg0, Integer arg1) {&lt;br /&gt;
Integer i = super.get(arg0);&lt;br /&gt;
arg1 = i==null?1:i+1;&lt;br /&gt;
return super.put(arg0, arg1);&lt;br /&gt;
}&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
String[] splits = inputString.split(&quot; &quot;);&lt;br /&gt;
for(String s : splits){&lt;br /&gt;
myMap.put(s,1);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
System.out.println(myMap);&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Source: &lt;a href=&quot;http://www.careercup.com/question?id=6175809&quot;&gt;Here&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/2050034179051786522/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2011/08/morgan-stanley-interview-question.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/2050034179051786522'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/2050034179051786522'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2011/08/morgan-stanley-interview-question.html' title='Morgan Stanley Interview Question'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-7259186263620784404</id><published>2011-08-17T19:49:00.000-07:00</published><updated>2011-08-17T19:50:38.438-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++ questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Hello World"/><category scheme="http://www.blogger.com/atom/ns#" term="interview questions"/><title type='text'>Interview Questions: wap to print &quot;hello world&quot; without reaching the main function in C++</title><content type='html'>There are several ways to do this:&lt;br /&gt;
&lt;br /&gt;
1. &lt;br /&gt;
&lt;pre&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;conio.h&amp;gt;
#define uttam main
uttam()
{
printf(&quot;hello world&quot;);
getch();
return 0;
}&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;2.&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;#include&amp;lt;stdio.h&amp;gt;
#define(s,t,u,m,p,e,d)m##s##u##t
#define begin decode(a,n,i,m,a,t,e)
int begin()
{
printf(&quot;Hello World&quot;);
}&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;3.&lt;/pre&gt;&lt;pre&gt;#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;iostream&amp;gt;

class World
{
 public:
 World()
 {
  printf(&quot;Hello world\n&quot;);
 }
};

World w1;

int main()
{
	printf(&quot;Hello world again!!\n&quot;);
	return 0;
}&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;source, click &lt;a href=&quot;http://www.allinterview.com/showanswers/83553/page2.html&quot;&gt;here&lt;/a&gt;.&amp;nbsp;&amp;nbsp; &lt;/pre&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/7259186263620784404/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2011/08/interview-questions-wap-to-print-hello.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/7259186263620784404'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/7259186263620784404'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2011/08/interview-questions-wap-to-print-hello.html' title='Interview Questions: wap to print &quot;hello world&quot; without reaching the main function in C++'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-4634185721149642056</id><published>2011-08-17T19:44:00.000-07:00</published><updated>2011-08-17T19:45:45.578-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="operating systems"/><category scheme="http://www.blogger.com/atom/ns#" term="Trading system"/><category scheme="http://www.blogger.com/atom/ns#" term="Unix"/><title type='text'>UNIX command Questions Answers asked in Interview</title><content type='html'>&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 24px; font-weight: bold;&quot;&gt;&lt;u&gt;&lt;span style=&quot;font-style: normal;&quot;&gt;UNIX command Questions Answers asked in Interview&lt;/span&gt;&lt;/u&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;b&gt;UNIX or &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD10&quot;&gt;Linux operating system&lt;/span&gt; &lt;/b&gt;has  become default Server operating system and for whichever programming  job you give interview you find some UNIX command interview questions  there. &lt;b&gt;These UNIX command interview questions&lt;/b&gt; are mostly asked during Java development and Support role interviews on various &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD9&quot;&gt;investment banks&lt;/span&gt; mostly because most of &lt;b&gt;electronic &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD3&quot;&gt;trading systems&lt;/span&gt;&lt;/b&gt; or &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD1&quot;&gt;stock trading system&lt;/span&gt; works on &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD6&quot;&gt;Unix servers&lt;/span&gt;.  As we know that high volume low latency systems which wants to take  advantage of little bit of volatility in market for Equity , Futures and  options or &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD2&quot;&gt;Foreign exchange trading&lt;/span&gt; need a stable server side operating system and Redhat Linux is doing great job there. with the advent of&lt;b&gt; &lt;/b&gt;&lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD4&quot;&gt;Algorithmic trading&lt;/span&gt;  this speed factor becomes more important so getting someone who has  good knowledge of operating system and commands on which these &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD5&quot;&gt;trading system&lt;/span&gt;  runs is definitely required. but these UNIX command interview questions  are equally applicable for any job interview which requires some work &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD7&quot;&gt;on Unix Operating System&lt;/span&gt;.  With the growing use of Linux in form of RedHat, Solaris and IBM AIX  its must to keep you familiar with essential Linux commands available on  various platforms.&amp;nbsp;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;Long  back I had once asked one of my friend why are you preparing Unix  Command interview questions if you going for a Java Interview and he  told me that this job doesn&#39;t only require knowledge of Java but also  knowledge of Unix, Linux, SQL and other scripting language , which is  quite true. After that I thought to collect various UNIX command  interview questions asked to Java developers or &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD8&quot;&gt;trading&lt;/span&gt; system  support interviews and this is the result of that compilation. This  list of UNIX command interview questions are by means complete and would  be great if you guys contribute some genuine and &lt;b&gt;good Unix Command Interview questions and answers &lt;/b&gt;asked during interviews. I have divided the questions on three categories for sake of managing and keeping this list of &lt;span class=&quot;IL_AD&quot; id=&quot;IL_AD11&quot;&gt;Unix Interview questions&lt;/span&gt; up to date.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;/div&gt;&lt;h3&gt;&lt;u&gt;Beginners UNIX Interview Questions Answers&lt;/u&gt;&lt;/h3&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;1. Write command to list all the links from a directory?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;In  this UNIX command interview questions interviewer is generally checking  whether user knows basic use of &quot;ls&quot; &quot;grep&quot; and regular expression etc&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;You can write command like:&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;ls -lrt | grep &quot;^l&quot;&lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;2. Create a read-only file in your home directory?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;This  is a simple UNIX command interview questions where you need to create a  file and change its parameter to read-only by using chmod command you  can also change your umask to create read only file. &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;touch file&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;chmod 400 file&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;3. How will you find which operating system your system is running on in UNIX?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;By using command &lt;b&gt;&quot;uname -a&quot; &lt;/b&gt;in UNIX&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;4. How will you run a process in background? How will you bring that into foreground and how will you kill that process?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;For running a process in background use &quot;&amp;amp;&quot; in command line. For bringing it back in foreground use command &quot;&lt;b&gt;fg jobid&quot; &lt;/b&gt;and  for getting job id you use command &quot;jobs&quot;, for killing that process  find PID and use kill -9 PID command. This is indeed a good Unix Command  interview questions because many of programmer not familiar with  background process in UNIX.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;5. How do you know if a remote host is alive or not?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;You can check these by using either &lt;b&gt;ping&lt;/b&gt; or &lt;b&gt;telnet&lt;/b&gt;  command in UNIX. This question is most asked in various Unix command  Interview because its most basic networking test anybody wants to do it.  &lt;/span&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;6. How do you see command line history in UNIX?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;Very useful indeed, use history command along with&lt;b&gt; &lt;a href=&quot;http://javarevisited.blogspot.com/2011/06/10-examples-of-grep-command-in-unix-and.html&quot;&gt;grep command in unix&lt;/a&gt;&amp;nbsp;&lt;/b&gt;to  find any relevant command you have already executed. Purpose of this  Unix Command Interview Questions is probably to check how familiar  candidate is from available tools in UNIX operation system.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;7. How do you copy file from one host to other?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;Many options but you can say by using &quot;&lt;b&gt;scp&lt;/b&gt;&quot; command. You can also use &lt;b&gt;rsync&lt;/b&gt; command to answer this UNIX interview question or even &lt;b&gt;sftp&lt;/b&gt; would be ok.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;8. How do you find which process is taking how much CPU?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;By  using &quot;top&quot; command in UNIX, there could be multiple follow-up UNIX  command interview questions based upon response of this because “TOP”  command has various interactive options to sort result based upon  various parameter.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;9. How do you check how much space left in current drive ?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;By using &lt;b&gt;&quot;df&quot;&lt;/b&gt; command in UNIX. For example &lt;b&gt;&quot;df -h .&quot;&lt;/b&gt;  will list how full your current drive is. This is part of anyone day to  day activity so I think this Unix Interview question will be to check  anyone who claims to working in UNIX but not really working on it.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;10. What is the difference between Swapping and Paging? &lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;Swapping: &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;Whole  process is moved from the swap device to the main memory for execution.  Process size must be less than or equal to the available main memory.  It is easier to implementation and overhead to the system. Swapping  systems does not handle the memory more flexibly as compared to the  paging systems. &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;Paging: &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;Only  the required memory pages are moved to main memory from the swap device  for execution. Process size does not matter. Gives the concept of the  virtual memory. It provides greater flexibility in mapping the virtual  address space into the physical memory of the machine. Allows more  number of processes to fit in the main memory simultaneously. Allows the  greater process size than the available physical memory. Demand paging  systems handle the memory more flexibly.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;&lt;h3&gt;&lt;u&gt;&lt;span style=&quot;color: black;&quot;&gt;Intermediate UNIX Interview Questions Answers&lt;/span&gt;&lt;/u&gt;&lt;/h3&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;1. What is difference between ps -ef and ps -auxwww?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;This  is indeed a good Unix Interview Command Question and I have faced this  issue while ago where one culprit process was not visible by execute &lt;b&gt;ps –ef&lt;/b&gt; command and we are wondering which process is holding the file.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;ps -ef will omit process with very long command line while ps -auxwww will list those process as well.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;2. How do you find how many cpu are in your system and there details?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;By looking into file /etc/cpuinfo for example you can use below command:&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;cat /proc/cpuinfo&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;3. What is difference between HardLink and SoftLink in UNIX?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;I have discussed this Unix Command Interview questions &amp;nbsp;in my blog post &lt;a href=&quot;http://javarevisited.blogspot.com/2011/04/symbolic-link-or-symlink-in-unix-linux.html&quot;&gt;difference between Soft link and Hard link in Unix&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;4. What is Zombie process in UNIX? How do you find Zombie process in UNIX?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;When  a program forks and the child finishes before the parent, the kernel  still keeps some of its information about the child in case the parent  might need it - for example, the parent may need to check the child&#39;s  exit status. To be able to get this information, the parent calls  &#39;wait()&#39;; In the interval between the child terminating and the parent  calling &#39;wait()&#39;, the child is said to be a &#39;zombie&#39; (If you do &#39;ps&#39;,  the child will have a &#39;Z&#39; in its status field to indicate this.) &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;Zombie : The process is dead but have not been removed from the process table.&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;5. What is &quot;chmod&quot; command? What do you understand by this line “r-- -w- --x?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;6.  There is a file some where in your system which contains word  &quot;UnixCommandInterviewQuestions” How will find that file in Unix?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;By using find command in UNIX for details see here &lt;a href=&quot;http://javarevisited.blogspot.com/2011/03/10-find-command-in-unix-examples-basic.html&quot;&gt;10 example of using find command in Unix&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;7. In a file word UNIX is appearing many times? How will you count number?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;grep -c &quot;Unix&quot; filename&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;8. How do you set environment variable which will be accessible form sub shell?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;By using &lt;b&gt;export&lt;/b&gt;&amp;nbsp; &amp;nbsp;for example export count=1 will be available on all sub shell.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;9. How do you check if a particular process is listening on a particular port on remote host?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;By  using telnet command for example “telnet hostname port”, if it able to  successfully connect then some process is listening on that port. To  read more about telnet read &lt;a href=&quot;http://javarevisited.blogspot.com/2010/10/basic-networking-commands-in-linuxunix.html&quot;&gt;networking command in UNIX&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;10. How do you find whether your system is 32 bit or 64 bit ?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;Either by using &lt;b&gt;&quot;uname -a&quot;&lt;/b&gt; command or by using &quot;&lt;b&gt;arch&lt;/b&gt;&quot; command.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;h3&gt;&lt;u&gt;&lt;span style=&quot;color: black;&quot;&gt;Advanced UNIX Interview Questions and Answers&lt;/span&gt;&lt;/u&gt;&lt;/h3&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;1. How do you find which processes are using a particular file?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;By using &lt;b&gt;lsof&lt;/b&gt; &lt;b&gt;command&lt;/b&gt; in UNIX. It wills list down PID of all the process which is using a particular file.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;2. How do you find which remote hosts are connecting to your host on a particular port say 10123?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;By using &lt;b&gt;netstat command&lt;/b&gt; execute netstat -a | grep &quot;port&quot; and it will list the entire host which is connected to this host on port 10123.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;3. What is nohup in UNIX?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;4. What is ephemeral port in UNIX?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;Ephemeral  ports are port used by Operating system for client sockets. There is a  specific range on which OS can open any port specified by ephemeral port  range.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;5. If one process is inserting data into your MySQL database? How will you check how many rows inserted into every second?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;Purpose of this Unix Command Interview is asking about &lt;b&gt;&quot;watch&quot; command&lt;/b&gt; in UNIX which is repeatedly execute command provided with specified delay.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;6. There is a file Unix_Test.txt which contains words Unix, how will you replace all Unix to UNIX? &lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;You can answer this Unix Command Interview question by using SED command in UNIX for example you can execute &lt;b&gt;sed s/Unix/UNIX/g fileName.&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;7.  You have a tab separated file which contains Name, Address and Phone  Number, list down all Phone Number without there name and Addresses?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;To  answer this Unix Command Interview question you can either you AWK or  CUT command here. CUT use tab as default separator so you can use &lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;cut -f3 filename.&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;8. Your application home directory is full? How will you find which directory is taking how much space?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;By using disk usage (DU) command in Unix for example du&lt;b&gt; –sh . | grep G&lt;/b&gt;&amp;nbsp; will list down all the directory which has GIGS in Size.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;9. How do you find for how many days your Server is up?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;By using &lt;b&gt;uptime&lt;/b&gt; command in UNIX&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;10. You have an IP address in your network how will you find hostname and vice versa?&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;This is a standard UNIX command interview question asked by everybody and I guess everybody knows its answer as well.&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;MsoNormal&quot;&gt;&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;By using &lt;b&gt;nslookup&lt;/b&gt; command in UNIX, you can read more about networking command in UNIX here.&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span style=&quot;color: black; font-family: Verdana; font-size: 8pt;&quot;&gt;Source: click &lt;a href=&quot;http://javarevisited.blogspot.com/2011/05/unix-command-interview-questions.html&quot;&gt;here&lt;/a&gt;. &lt;/span&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/4634185721149642056/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2011/08/unix-command-questions-answers-asked-in.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/4634185721149642056'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/4634185721149642056'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2011/08/unix-command-questions-answers-asked-in.html' title='UNIX command Questions Answers asked in Interview'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-4505329235157423298</id><published>2011-06-24T18:50:00.000-07:00</published><updated>2011-06-24T18:50:55.617-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="encapsulation"/><category scheme="http://www.blogger.com/atom/ns#" term="inheritance"/><category scheme="http://www.blogger.com/atom/ns#" term="OOP"/><category scheme="http://www.blogger.com/atom/ns#" term="polymorphism"/><title type='text'>Insight of OOP Object -- How inheritance, encapsulation and polymorphism work</title><content type='html'>&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;&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;&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;&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;br /&gt;
&lt;h2&gt;How inheritance, encapsulation and polymorphism work in C++&lt;/h2&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;&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;&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;&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;&amp;nbsp; &lt;a href=&quot;http://www.alexonlinux.com%20/&quot;&gt;alexonlinux.com &lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;h1&gt;Table of contents&lt;/h1&gt;&lt;div class=&quot;toc&quot;&gt;&lt;a href=&quot;&quot; name=&quot;table_of_contents&quot; title=&quot;table_of_contents&quot;&gt;&lt;/a&gt;&lt;a class=&quot;toc_h1&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#introduction&quot;&gt;Introduction&lt;/a&gt;&lt;br /&gt;
&lt;a class=&quot;toc_h1&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#encapsulation&quot;&gt;Encapsulation&lt;/a&gt;&lt;br /&gt;
&lt;a class=&quot;toc_h2&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#how_methods_work&quot;&gt;How methods work&lt;/a&gt;&lt;br /&gt;
&lt;a class=&quot;toc_h2&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#how_overloading_works&quot;&gt;How overloading works&lt;/a&gt;&lt;br /&gt;
&lt;a class=&quot;toc_h3&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#how_mangling_solves_the_problem&quot;&gt;How mangling solves the problem&lt;/a&gt;&lt;br /&gt;
&lt;a class=&quot;toc_h2&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#structure_and_size_of_the_object&quot;&gt;Structure and size of the object&lt;/a&gt;&lt;br /&gt;
&lt;a class=&quot;toc_h1&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#how_inheritance_and_polymorphism_work&quot;&gt;How inheritance and polymorphism work&lt;/a&gt;&lt;br /&gt;
&lt;a class=&quot;toc_h2&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#how_basic_polymorphism_works&quot;&gt;How basic polymorphism works&lt;/a&gt;&lt;br /&gt;
&lt;a class=&quot;toc_h2&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#how_multiple_inheritance_works&quot;&gt;How multiple inheritance works&lt;/a&gt;&lt;br /&gt;
&lt;a class=&quot;toc_h3&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#difference_between_different_casting_types&quot;&gt;Difference between different casting types&lt;/a&gt;&lt;br /&gt;
&lt;a class=&quot;toc_h2&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#polymorphism_and_multiple_inheritance&quot;&gt;Polymorphism and multiple inheritance&lt;/a&gt;&lt;br /&gt;
&lt;a class=&quot;toc_h3&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#what_if_we_try_something_even_more_complicated&quot;&gt;What if we try something even more complicated&lt;/a&gt;&lt;br /&gt;
&lt;a class=&quot;toc_h2&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#few_words_about_c++_constructors&quot;&gt;Few words about C++ constructors&lt;/a&gt;&lt;br /&gt;
&lt;a class=&quot;toc_h1&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#conclusion&quot;&gt;Conclusion&lt;/a&gt;&lt;br /&gt;
&lt;/div&gt;&lt;h1&gt;&lt;a href=&quot;&quot; name=&quot;introduction&quot; title=&quot;introduction&quot;&gt;&lt;/a&gt;Introduction&lt;a class=&quot;toc_top&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#table_of_contents&quot;&gt;BACK TO TOC&lt;/a&gt;&lt;/h1&gt;Inheritance, encapsulation and polymorphism are undoubtedly the cornerstones of OOP/OOD in general and C++ in particular.&lt;br /&gt;
When programming C, it is very easy to remember how things work. You know that when you add an &lt;em&gt;int&lt;/em&gt; variable to a structure it mostly grows by four bytes. You know that &lt;em&gt;long&lt;/em&gt; is either four or eight bytes long depending on the architecture you’re working with.&lt;br /&gt;
Things are less obvious when moving to C++. OOP brings more  abstractions to the program. As a result you are no longer sure if a+b  sums two numbers or calls some overloaded operator method that  concatenates contents of two files together.&lt;br /&gt;
In this article, I would like to give you a short insight into what’s  going on behind the scenes. In particular we’ll see how the three  whales of OOP work in C++.&lt;br /&gt;
Things that I am going to show in this article may differ from  compiler to compiler. I will talk mostly about g++ (version 4.2.3). Note  however, that same ideas apply everywhere.&lt;br /&gt;
&lt;h1&gt;&lt;a href=&quot;&quot; name=&quot;encapsulation&quot; title=&quot;encapsulation&quot;&gt;&lt;/a&gt;Encapsulation&lt;a class=&quot;toc_top&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#table_of_contents&quot;&gt;BACK TO TOC&lt;/a&gt;&lt;/h1&gt;As you know, encapsulation is a principle by which same entity, the  object, encapsulates data and methods that manipulate the data. You may  be surprised to find out that underneath, class methods are just plain  functions.&lt;br /&gt;
&lt;h2&gt;&lt;a href=&quot;&quot; name=&quot;how_methods_work&quot; title=&quot;how_methods_work&quot;&gt;&lt;/a&gt;How methods work&lt;a class=&quot;toc_top&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#table_of_contents&quot;&gt;BACK TO TOC&lt;/a&gt;&lt;/h2&gt;In C++ there’s one fundamental difference between plain functions and  class methods. Class methods receive one additional argument and that  is the pointer to the object whose data the method is expected to  manipulate. I.e. first argument to a method is pointer to &lt;em&gt;this&lt;/em&gt;.&lt;br /&gt;
To speed things up, C++ developers used single CPU register (ECX/RCX on x86/x86_64) to pass pointer to &lt;em&gt;this&lt;/em&gt;, instead of passing it via stack as if it was a regular function argument (no longer true in x86_64).&lt;br /&gt;
Otherwise, objects know nothing about methods that operate on them.&lt;br /&gt;
&lt;h2&gt;&lt;a href=&quot;&quot; name=&quot;how_overloading_works&quot; title=&quot;how_overloading_works&quot;&gt;&lt;/a&gt;How overloading works&lt;a class=&quot;toc_top&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#table_of_contents&quot;&gt;BACK TO TOC&lt;/a&gt;&lt;/h2&gt;Another thing that we have to take care of in C++ is how to distinguish between &lt;em&gt;some_function()&lt;/em&gt; and &lt;em&gt;some_class::some_function()&lt;/em&gt;. Or between &lt;em&gt;some_class::some_function( int ) &lt;/em&gt;and &lt;em&gt;some_class::some_function()&lt;/em&gt;  I.e. what’s the difference between two methods with the same name that  receive different number and type of arguments? What is the difference  between method and function that has same name?&lt;br /&gt;
Obviously, out of linker, compiler and preprocessor, linker is the  one that should be aware of the above difference. This is because we may  have &lt;em&gt;some_function()&lt;/em&gt; in some distant object file. Linker is  the component that should find this distant function and interconnect  the call to the function and the actual function. Linker uses function  name as a unique identifier of the function.&lt;br /&gt;
To make things work, g++ and any other modern compiler, mangles the name of the method/function and makes sure that:&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;Mangled method name includes name of the class it belongs to (if it belongs to any class).&lt;/li&gt;
&lt;li&gt;Mangled method name includes number and type of arguments method receives.&lt;/li&gt;
&lt;li&gt;Mangled method name includes namespace it belongs to.&lt;/li&gt;
&lt;/ol&gt;With these three, &lt;em&gt;some_class::some_function()&lt;/em&gt; and &lt;em&gt;some_function()&lt;/em&gt; will have totally different mangled name. See the following code sample.&lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter  &quot; id=&quot;highlighter_290724&quot;&gt;&lt;div class=&quot;lines&quot;&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;01&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;namespace&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;some_namespace&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;02&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;03&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;class&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;some_class&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;04&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;05&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;public&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;:&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;06&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;some_class() { }&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;07&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;void&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;some_method() { }&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;08&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;};&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;09&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;};&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;10&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;11&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;class&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;some_class&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;12&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;13&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;public&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;:&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;14&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;some_class() { }&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;15&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;void&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;some_method() { }&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;16&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;};&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;17&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;18&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;void&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;some_method()&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;19&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;20&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;a;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;21&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;g++ will turn:&lt;br /&gt;
&lt;ul&gt;&lt;li&gt;&lt;em&gt;void &lt;/em&gt;&lt;em&gt;some_class::some_method() &lt;/em&gt;into &lt;em&gt;_ZN10some_class11some_methodEv&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;void some_namespace::some_class::some_method() &lt;/em&gt;into &lt;em&gt;_ZN14some_namespace10some_class11some_methodEv&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;void some_method()&lt;/em&gt; into &lt;em&gt;_Z11some_methodv&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;Adding integer argument to &lt;em&gt;void some_method()&lt;/em&gt; will turn it from &lt;em&gt;_Z11some_methodv &lt;/em&gt;to &lt;em&gt;_Z11some_methodi&lt;/em&gt;.&lt;br /&gt;
&lt;h3&gt;&lt;a href=&quot;&quot; name=&quot;how_mangling_solves_the_problem&quot; title=&quot;how_mangling_solves_the_problem&quot;&gt;&lt;/a&gt;How mangling solves the problem&lt;a class=&quot;toc_top&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#table_of_contents&quot;&gt;BACK TO TOC&lt;/a&gt;&lt;/h3&gt;So when you create two methods with same name, but with different  arguments, compiler turns them into two functions with different names.  Later, when linker links the code together it doesn’t know that these  are two methods of the same class. From linkers standpoint, these are  two different functions.&lt;br /&gt;
&lt;h2&gt;&lt;a href=&quot;&quot; name=&quot;structure_and_size_of_the_object&quot; title=&quot;structure_and_size_of_the_object&quot;&gt;&lt;/a&gt;Structure and size of the object&lt;a class=&quot;toc_top&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#table_of_contents&quot;&gt;BACK TO TOC&lt;/a&gt;&lt;/h2&gt;You probably already know that C++ class and good old C structures  are nearly the same thing. Perhaps the only difference is that all class  members are private unless specified otherwise. On the contrary, all  structure members are public.&lt;br /&gt;
When looking at the memory layout of the object, it is very similar to C structure.&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-566&quot; height=&quot;201&quot; src=&quot;http://www.alexandersandler.net/wp-content/uploads/2008/09/object_structure1.png&quot; title=&quot;Object vs. structure&quot; width=&quot;547&quot; /&gt;&lt;/div&gt;Differences begin when you add virtual methods. Once you add virtual  methods to the class, compiler will create virtual methods table for the  class. Then it will place pointer to the table in the beginning of each  instance of this class.&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-568&quot; height=&quot;221&quot; src=&quot;http://www.alexandersandler.net/wp-content/uploads/2008/09/object_structure2.png&quot; title=&quot;Object vs. structure and virtual methods table&quot; width=&quot;547&quot; /&gt;&lt;/div&gt;So, bear in mind that once your class has virtual methods, each  object of this class will be four or eight bytes (depends on whether you  have 64-bit support or not) bigger.&lt;br /&gt;
Actually, pointer to the virtual methods table does not have to be at  the beginning of the object. It is just handy to keep it at the  beginning, so g++ and most of the modern compilers do it this way.&lt;br /&gt;
Adding virtual methods to the class will also increase amount of RAM your program consumes and its size on your hard drive.&lt;br /&gt;
&lt;h1&gt;&lt;a href=&quot;&quot; name=&quot;how_inheritance_and_polymorphism_work&quot; title=&quot;how_inheritance_and_polymorphism_work&quot;&gt;&lt;/a&gt;How inheritance and polymorphism work&lt;a class=&quot;toc_top&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#table_of_contents&quot;&gt;BACK TO TOC&lt;/a&gt;&lt;/h1&gt;Lets say we have two classes. A and B. Class B inherits from class A.&lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter  &quot; id=&quot;highlighter_472849&quot;&gt;&lt;div class=&quot;lines&quot;&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;01&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;preprocessor&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;02&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;03&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;using&lt;/code&gt; &lt;code class=&quot;keyword bold&quot;&gt;namespace&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;std;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;04&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;05&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;class&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;A&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;06&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;07&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;public&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;:&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;08&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;A() { a_member = 0; }&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;09&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;a_member;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;10&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;};&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;11&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;12&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;class&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;B : &lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;A&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;13&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;14&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;public&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;:&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;15&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;B() : A() { b_member = 0; };&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;16&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;b_member;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;17&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;};&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;18&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;19&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;main()&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;20&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;21&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;A *a = &lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;new&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;B;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;22&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;a-&amp;gt;a_member = 10;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;23&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;24&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;return&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;0;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;25&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;The interesting thing to notice here is that &lt;em&gt;a&lt;/em&gt; actually points to instance of class B. When dereferencing &lt;em&gt;a_member&lt;/em&gt;, we’re actually dereferencing &lt;em&gt;a_member&lt;/em&gt;  that defined in class A, but belongs to class B (via inheritance). To  make this happen, compiler has to make sure that common part of both  classes (&lt;em&gt;a_member&lt;/em&gt; in our case) located at the same offset in the object.&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-570&quot; height=&quot;141&quot; src=&quot;http://www.alexandersandler.net/wp-content/uploads/2008/09/a_b1.png&quot; title=&quot;Classes A and B&quot; width=&quot;547&quot; /&gt;&lt;/div&gt;Now what if we have some virtual methods.&lt;br /&gt;
&lt;h2&gt;&lt;a href=&quot;&quot; name=&quot;how_basic_polymorphism_works&quot; title=&quot;how_basic_polymorphism_works&quot;&gt;&lt;/a&gt;How basic polymorphism works&lt;a class=&quot;toc_top&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#table_of_contents&quot;&gt;BACK TO TOC&lt;/a&gt;&lt;/h2&gt;Let’s change our example a bit and add some virtual methods.&lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter  &quot; id=&quot;highlighter_30977&quot;&gt;&lt;div class=&quot;lines&quot;&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;01&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;preprocessor&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;02&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;03&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;using&lt;/code&gt; &lt;code class=&quot;keyword bold&quot;&gt;namespace&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;std;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;04&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;05&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;class&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;A&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;06&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;07&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;public&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;:&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;08&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;A() { a_member = 0; }&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;09&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;virtual&lt;/code&gt; &lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;reset() { a_member = 0; }&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;10&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;void&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;set_a_member( &lt;/code&gt;&lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;a ) { a_member = a; }&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;11&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;get_a_member() { &lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;return&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;a_member; }&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;12&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;protected&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;:&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;13&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;a_member;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;14&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;};&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;15&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;16&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;class&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;B : &lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;A&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;17&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;18&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;public&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;:&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;19&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;B() : A() { b_member = 0; };&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;20&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;virtual&lt;/code&gt; &lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;reset() { a_member = b_member = 0; }&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;21&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;virtual&lt;/code&gt; &lt;code class=&quot;keyword bold&quot;&gt;void&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;some_virtual_method() { }&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;22&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;void&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;set_b_member(&lt;/code&gt;&lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;b ) { b_member = b; }&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;23&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;get_b_member() { &lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;return&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;b_member; }&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;24&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;protected&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;:&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;25&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;b_member;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;26&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;};&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;27&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;28&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;main()&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;29&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;30&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;B *b = &lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;new&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;B;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;31&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;A *a = b;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;32&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;33&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;b-&amp;gt;set_b_member( 20 );&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;34&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;b-&amp;gt;set_a_member( 10 );&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;35&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;36&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;a-&amp;gt;reset();&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;37&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;38&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;cout &amp;lt;&amp;lt; b-&amp;gt;get_a_member() &amp;lt;&amp;lt; &lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot; &quot;&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;&amp;lt;&amp;lt; b-&amp;gt;get_b_member() &amp;lt;&amp;lt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;39&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;endl;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;40&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;41&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;return&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;0;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;42&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;If you compile and run this program it will obviously print “0 0″. But how, you may ask. After all we did &lt;em&gt;a-&amp;gt;reset()&lt;/em&gt;. Without our understanding of polymorphism we could think that we’re calling method that belongs to class A.&lt;br /&gt;
The reason it works is because when compiler sees code that  dereferences pointer to A it expects certain internal object structure  and when it dereferences pointer to B it expects different object  structure. Let us take a look at both of them.&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;size-full wp-image-574 aligncenter&quot; height=&quot;161&quot; src=&quot;http://www.alexandersandler.net/wp-content/uploads/2008/09/a_b2.png&quot; title=&quot;Classes A and B with virtual methods tables&quot; width=&quot;547&quot; /&gt;&lt;/div&gt;However even more important here is the structure of the virtual methods tables of both classes.&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-576&quot; height=&quot;141&quot; src=&quot;http://www.alexandersandler.net/wp-content/uploads/2008/09/a_b_virtuals.png&quot; title=&quot;Classes A and B virtual methods tables&quot; width=&quot;547&quot; /&gt;&lt;/div&gt;It is because of the virtual methods table structure compilers knows  what virtual method to call. When it generates the code that  dereferences pointer to A, it expects that first method in the virtual  methods table of the object will be pointer to right &lt;em&gt;reset()&lt;/em&gt;  routine. It doesn’t really care if the pointer actually points to B  object. It will call first method of the virtual methods table anyway.&lt;br /&gt;
&lt;h2&gt;&lt;a href=&quot;&quot; name=&quot;how_multiple_inheritance_works&quot; title=&quot;how_multiple_inheritance_works&quot;&gt;&lt;/a&gt;How multiple inheritance works&lt;a class=&quot;toc_top&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#table_of_contents&quot;&gt;BACK TO TOC&lt;/a&gt;&lt;/h2&gt;Multiple inheritance makes things much more complicated. The problem  is that when class C inherits from both A and B, we should have both  members of class A and class B in the instance of class C.&lt;br /&gt;
&lt;div class=&quot;syntaxhighlighter  &quot; id=&quot;highlighter_966342&quot;&gt;&lt;div class=&quot;lines&quot;&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;01&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;preprocessor&quot;&gt;#include &amp;lt;iostream&amp;gt;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;02&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;03&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;using&lt;/code&gt; &lt;code class=&quot;keyword bold&quot;&gt;namespace&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;std;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;04&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;05&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;class&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;A&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;06&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;07&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;public&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;:&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;08&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;A() { a_member = 0; }&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;09&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;protected&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;:&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;10&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;a_member;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;11&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;};&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;12&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;13&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;class&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;B&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;14&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;15&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;public&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;:&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;16&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;B() { b_member = 0; }&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;17&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;protected&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;:&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;18&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;b_member;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;19&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;};&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;20&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;21&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;class&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;C : &lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;A, &lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;public&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;B&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;22&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;23&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;public&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;:&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;24&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;C() : A(), B() { c_member = 0; }&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;25&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;keyword bold&quot;&gt;protected&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;:&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;26&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;c_member;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;27&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;};&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;28&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;29&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;color1 bold&quot;&gt;int&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;main()&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;30&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;{&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;31&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;C c;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;32&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;33&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;A *a1 = &amp;amp;c;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;34&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;B *b1 = &amp;amp;c;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;35&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;36&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;A *a2 = &lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;reinterpret_cast&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;A *&amp;gt;( &amp;amp;c );&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;37&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;B *b2 = &lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;reinterpret_cast&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;&amp;lt;B *&amp;gt;( &amp;amp;c );&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;38&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;39&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;functions bold&quot;&gt;printf&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;( &lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;%p %p %p\n&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;, &amp;amp;c, a1, b1 );&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;40&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;functions bold&quot;&gt;printf&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;( &lt;/code&gt;&lt;code class=&quot;string&quot;&gt;&quot;%p %p %p\n&quot;&lt;/code&gt;&lt;code class=&quot;plain&quot;&gt;, &amp;amp;c, a2, b2 );&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;41&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&amp;nbsp;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt2&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;42&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;spaces&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/code&gt;&lt;code class=&quot;keyword bold&quot;&gt;return&lt;/code&gt; &lt;code class=&quot;plain&quot;&gt;0;&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;div class=&quot;line alt1&quot;&gt;&lt;table&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td class=&quot;number&quot;&gt;&lt;code&gt;43&lt;/code&gt;&lt;/td&gt;&lt;td class=&quot;content&quot;&gt;&lt;code class=&quot;plain&quot;&gt;}&lt;/code&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-579&quot; height=&quot;261&quot; src=&quot;http://www.alexandersandler.net/wp-content/uploads/2008/09/inheritance1.png&quot; title=&quot;Simple dual inheritance&quot; width=&quot;547&quot; /&gt;&lt;/div&gt;Once we cast pointer to class C into class B, we cannot keep the  value of the pointer as is because first fields in the object occupied  by fields defined in class A (&lt;em&gt;a_member&lt;/em&gt;). Therefore, when we do  casting we have to do a very special kind of casting – the one that  changes the actual value of the pointer.&lt;br /&gt;
If you compile and run above code snippet, you will see that all the  values are the same except for b1, which should be 4 bytes bigger than  other values.&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-584&quot; height=&quot;261&quot; src=&quot;http://www.alexandersandler.net/wp-content/uploads/2008/09/inheritance2.png&quot; title=&quot;Dual inheritance&quot; width=&quot;547&quot; /&gt;&lt;/div&gt;This is what (C style casting in our case) casting does – it  increments the value of the pointer to make sure that it points to the  beginning of the, inherited from B, part of the object.&lt;br /&gt;
In case you wonder what other types of casting will do, here is a short description.&lt;br /&gt;
&lt;h3&gt;&lt;a href=&quot;&quot; name=&quot;difference_between_different_casting_types&quot; title=&quot;difference_between_different_casting_types&quot;&gt;&lt;/a&gt;Difference between different casting types&lt;a class=&quot;toc_top&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#table_of_contents&quot;&gt;BACK TO TOC&lt;/a&gt;&lt;/h3&gt;There are five types of casting in C++.&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;reinterpret_cast&amp;lt;&amp;gt;()&lt;/li&gt;
&lt;li&gt;static_cast&amp;lt;&amp;gt;()&lt;/li&gt;
&lt;li&gt;dynamic_cast&amp;lt;&amp;gt;()&lt;/li&gt;
&lt;li&gt;const_cast&amp;lt;&amp;gt;()&lt;/li&gt;
&lt;li&gt;C style cast.&lt;/li&gt;
&lt;/ol&gt;I guess you know already what const_cast&amp;lt;&amp;gt;() does. Also, it is  only a compile time casting. C style cast is same as  static_cast&amp;lt;&amp;gt;(). This leaves us with three types of casting.&lt;br /&gt;
&lt;ol&gt;&lt;li&gt;reinterpret_cast&amp;lt;&amp;gt;()&lt;/li&gt;
&lt;li&gt;static_cast&amp;lt;&amp;gt;()&lt;/li&gt;
&lt;li&gt;dynamic_cast&amp;lt;&amp;gt;()&lt;/li&gt;
&lt;/ol&gt;From the above example we learn that reinterpret_cast&amp;lt;&amp;gt;() does nothing to the pointer value and leaves it as is.&lt;br /&gt;
static_cast&amp;lt;&amp;gt;() and dynamic_cast&amp;lt;&amp;gt;() both modify value of  the pointer. The difference between two is that the later relies on  RTTI to see if the casting is legal – it looks inside the object to see  if it truly belongs to the type we’re trying to cast from.  static_cast&amp;lt;&amp;gt;() on the other hand, simply increments the value of  the pointer.&lt;br /&gt;
&lt;h2&gt;&lt;a href=&quot;&quot; name=&quot;polymorphism_and_multiple_inheritance&quot; title=&quot;polymorphism_and_multiple_inheritance&quot;&gt;&lt;/a&gt;Polymorphism and multiple inheritance&lt;a class=&quot;toc_top&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#table_of_contents&quot;&gt;BACK TO TOC&lt;/a&gt;&lt;/h2&gt;Things getting even more complicated when we have virtual methods in  each one of the classes A, B and C that we already met. Let’s add  following virtual methods to the classes.&lt;br /&gt;
&lt;pre&gt;virtual void set_a( int new_a ) { a_member = new_a; }&lt;/pre&gt;To class A.&lt;br /&gt;
&lt;pre&gt;virtual void set_b( int new_b ) { b_member = new_b; }&lt;/pre&gt;To class B and&lt;br /&gt;
&lt;pre&gt;virtual void set_c( int new_c ) { c_member = new_c; }&lt;/pre&gt;To class C.&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-587&quot; height=&quot;461&quot; src=&quot;http://www.alexandersandler.net/wp-content/uploads/2008/09/inheritance3.png&quot; title=&quot;Dual inheritance with virtual methods table&quot; width=&quot;547&quot; /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;You could have assumed that even in this  case class C objects will have only one virtual tables methods, but this  is not true. When you static_cast class C object into class B object,  class B object must have its own virtual tables method. If we want to  use same casting method as with regular objects (that is adding few  bytes to the pointer to reach right portion of the object), then we have  no choice but to place another virtual tables method in the middle of  the object.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;As a result, you can have many different  virtual methods tables for the same class. The above diagram shows very  simple case of inheritance and the truth is that it does not get more  complicated than this. Take a look at the following, more complex, class  hierarchy.&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-594&quot; height=&quot;361&quot; src=&quot;http://www.alexandersandler.net/wp-content/uploads/2008/09/hierarchy1.png&quot; title=&quot;Complex hierarchy of classes&quot; width=&quot;469&quot; /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;It may surprise you, but structure of the  class X object will be quiet simple. In our previous example inheritance  hierarchy had two branches. This one has three:&lt;/div&gt;&lt;ol&gt;&lt;li&gt;A-C-F-X&lt;/li&gt;
&lt;li&gt;D-G-X&lt;/li&gt;
&lt;li&gt;B-E-H-X&lt;/li&gt;
&lt;/ol&gt;All end up with X of course. They are a little longer than in our  previous example, but there is nothing special about them. The structure  of the object will be the following:&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-597&quot; height=&quot;341&quot; src=&quot;http://www.alexandersandler.net/wp-content/uploads/2008/09/classx.png&quot; title=&quot;Structure of derivative of the hierarchy&quot; width=&quot;365&quot; /&gt;&lt;/div&gt;As a rule of thumb, g++ (and friends) calculates the branches that  lead to the target class, class X in our case. Next it creates a virtual  methods table for each branch and places all virtual methods from all  classes in the branch into virtual methods table. This includes pointer  to virtual methods of the class itself.&lt;br /&gt;
If we project this rule onto our last example. A-C-F-X branch virtual  methods table will include pointers to virtual methods from classes A,  C, F and X. Same with other two branches.&lt;br /&gt;
&lt;h3&gt;&lt;a href=&quot;&quot; name=&quot;what_if_we_try_something_even_more_complicated&quot; title=&quot;what_if_we_try_something_even_more_complicated&quot;&gt;&lt;/a&gt;What if we try something even more complicated&lt;a class=&quot;toc_top&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#table_of_contents&quot;&gt;BACK TO TOC&lt;/a&gt;&lt;/h3&gt;The thing is that you can’t. Lets say we try to create even more  complicated hierarchy by changing class D from our previous example to  inherit from class C.&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;&quot; class=&quot;aligncenter size-full wp-image-601&quot; height=&quot;361&quot; src=&quot;http://www.alexandersandler.net/wp-content/uploads/2008/09/hierarchy2.png&quot; title=&quot;Ambiguous hierarchy of classes&quot; width=&quot;469&quot; /&gt;&lt;/div&gt;This will immediately create ambiguous inheritance and the compiler  will not hesitate to tell you that this is what happened. This is  because now class X will have all members of classes A and C twice. Once  it will have it via A-C-F-X branch and once via A-C-D-G-X branch. It  will not tell you that there’s a problem immediately. Instead, once you  will try to reference one of the members of X inherited from either A or  C, g++ will tell you that it has two variations of the same  member/method and that it does not know which one of them to call.&lt;br /&gt;
This what would be g++ output if you try to compile &lt;a href=&quot;http://www.alexandersandler.net/wp-content/uploads/2008/09/main.cc&quot;&gt;this file&lt;/a&gt;.&lt;br /&gt;
&lt;pre&gt;main.cc: In function &#39;int main()&#39;:
main.cc:110: error: request for member &#39;set_a&#39; is ambiguous
main.cc:29: error: candidates are: virtual void A::set_a(int)
main.cc:29: error:                 virtual void A::set_a(int)&lt;/pre&gt;All this because I was trying to do &lt;em&gt;x.set_a( 20 );&lt;/em&gt; in line 110.&lt;br /&gt;
&lt;h2&gt;&lt;a href=&quot;&quot; name=&quot;few_words_about_c++_constructors&quot; title=&quot;few_words_about_c++_constructors&quot;&gt;&lt;/a&gt;Few words about C++ constructors&lt;a class=&quot;toc_top&quot; href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp#table_of_contents&quot;&gt;BACK TO TOC&lt;/a&gt;&lt;/h2&gt;I guess you know what constructors are good for. In light of what  we’ve seen, you may ask yourself, who is building all those virtual  methods tables and who writes right pointer into the object.&lt;br /&gt;
Obviously compiler builds all the virtual methods tables. And  constructor is the one who fills in the right virtual methods table. And  this is another reason why you cannot call constructor directly – you  don’t want to mess up with virtual methods tables.&lt;br /&gt;
&lt;br /&gt;
Source: Click &lt;a href=&quot;http://www.alexonlinux.com/how-inheritance-encapsulation-and-polymorphism-work-in-cpp&quot;&gt;here &lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/4505329235157423298/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2011/06/insight-of-oop-object-how-inheritance.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/4505329235157423298'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/4505329235157423298'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2011/06/insight-of-oop-object-how-inheritance.html' title='Insight of OOP Object -- How inheritance, encapsulation and polymorphism work'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-7914244211443336009</id><published>2011-06-22T18:36:00.000-07:00</published><updated>2011-06-22T18:38:13.285-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Basic Questions"/><category scheme="http://www.blogger.com/atom/ns#" term="Interview"/><category scheme="http://www.blogger.com/atom/ns#" term="Java"/><title type='text'>Java Interview Questions - Basic Questions</title><content type='html'>&lt;span class=&quot;que&quot;&gt;&lt;span class=&quot;queIndex&quot;&gt;1.&lt;/span&gt;&lt;b&gt;What is Constructor&lt;/b&gt;?&lt;/span&gt;  &lt;br /&gt;
&lt;ul&gt;&lt;li&gt;A constructor is a special method whose task is to initialize the object of its class.&lt;/li&gt;
&lt;li&gt;It is special because its name is the &lt;b&gt;same as the class name&lt;/b&gt;. &lt;/li&gt;
&lt;li&gt;They do not have return types, not even &lt;b&gt;void&lt;/b&gt; and therefore they cannot return values.&lt;/li&gt;
&lt;li&gt;They &lt;b&gt;cannot be inherited&lt;/b&gt;, though a derived class can call the base class constructor. &lt;/li&gt;
&lt;li&gt;Constructor is invoked whenever an object of its associated class is created.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;span class=&quot;que&quot;&gt;&lt;span class=&quot;queIndex&quot;&gt;2.&lt;/span&gt;&lt;b&gt;How does the Java default constructor be  provided?&lt;/b&gt;&lt;/span&gt; &lt;br /&gt;
&lt;div align=&quot;justify&quot; class=&quot;content&quot;&gt;If  a class defined by the code does &lt;b&gt;not&lt;/b&gt;  have any constructor, compiler will  automatically provide one  no-parameter-constructor (default-constructor) for  the class in the  byte code. The access modifier (public/private/etc.) of the  default  constructor is the same as the class itself.&lt;/div&gt;&lt;br /&gt;
&lt;span class=&quot;que&quot;&gt;&lt;span class=&quot;queIndex&quot;&gt;3.&lt;/span&gt;&lt;b&gt;Can constructor be inherited&lt;/b&gt;?&lt;/span&gt; &lt;br /&gt;
&lt;div align=&quot;justify&quot; class=&quot;content&quot;&gt;No,  constructor cannot be inherited, though a derived class can call the base class  constructor.&lt;/div&gt;&lt;br /&gt;
&lt;span class=&quot;que&quot;&gt;      &lt;span class=&quot;queIndex&quot;&gt;4.&lt;/span&gt;&lt;b&gt;What are the differences between  Contructors and Methods?&lt;/b&gt;&lt;/span&gt;     &lt;br /&gt;
&lt;div align=&quot;justify&quot; class=&quot;content&quot;&gt;&lt;/div&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;5&quot; cellspacing=&quot;5&quot; class=&quot;mytable&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;     &lt;th width=&quot;18%&quot;&gt;&lt;/th&gt;     &lt;th width=&quot;41%&quot;&gt;&lt;b&gt;Constructors&lt;/b&gt;&lt;/th&gt;      &lt;th width=&quot;41%&quot;&gt;&lt;b&gt;Methods&lt;/b&gt;&lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;     &lt;td valign=&quot;top&quot; width=&quot;97&quot;&gt;&lt;b&gt;Purpose&lt;/b&gt;&lt;/td&gt;     &lt;td valign=&quot;top&quot;&gt;Create  an instance of a class&lt;/td&gt;     &lt;td valign=&quot;top&quot;&gt;Group  Java statements&lt;/td&gt;   &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign=&quot;top&quot; width=&quot;97&quot;&gt;&lt;b&gt;Modifiers&lt;/b&gt;&lt;/td&gt;     &lt;td valign=&quot;top&quot;&gt;Cannot  be &lt;i&gt;abstract, final, native, static&lt;/i&gt;, or &lt;i&gt;synchronized&lt;/i&gt;&lt;/td&gt;     &lt;td valign=&quot;top&quot;&gt;Can  be &lt;i&gt;abstract, final, native, static&lt;/i&gt;, or &lt;i&gt;synchronized&lt;/i&gt;&lt;/td&gt;   &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign=&quot;top&quot; width=&quot;97&quot;&gt;&lt;b&gt;Return Type&lt;/b&gt;&lt;/td&gt;     &lt;td valign=&quot;top&quot;&gt;No  return type, not even void&lt;/td&gt;     &lt;td valign=&quot;top&quot;&gt;void  or a valid return type&lt;/td&gt;   &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign=&quot;top&quot; width=&quot;97&quot;&gt;&lt;b&gt;Name&lt;/b&gt;&lt;/td&gt;     &lt;td valign=&quot;top&quot;&gt;Same  name as the class (first letter is capitalized by convention) -- usually a noun&lt;/td&gt;     &lt;td valign=&quot;top&quot;&gt;Any  name except the class. Method names begin with a lowercase letter by convention  -- usually the name of an action&lt;/td&gt;   &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign=&quot;top&quot; width=&quot;97&quot;&gt;&lt;b&gt;&lt;i&gt;this&lt;/i&gt;&lt;/b&gt;&lt;/td&gt;     &lt;td valign=&quot;top&quot;&gt;Refers  to another constructor in the same class. If used, it must be the first line of  the constructor&lt;/td&gt;     &lt;td valign=&quot;top&quot;&gt;Refers  to an instance of the owning class. Cannot be used by static methods.&lt;/td&gt;   &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign=&quot;top&quot; width=&quot;97&quot;&gt;&lt;b&gt;&lt;i&gt;super&lt;/i&gt;&lt;/b&gt;&lt;/td&gt;     &lt;td valign=&quot;top&quot;&gt;Calls  the constructor of the parent class. If used, must be the first line of the  constructor&lt;/td&gt;     &lt;td valign=&quot;top&quot;&gt;Calls  an overridden method in the parent class&lt;/td&gt;   &lt;/tr&gt;
&lt;tr&gt;     &lt;td valign=&quot;top&quot; width=&quot;97&quot;&gt;&lt;b&gt;Inheritance&lt;/b&gt;&lt;/td&gt;     &lt;td valign=&quot;top&quot;&gt;Constructors  are not inherited&lt;/td&gt;     &lt;td valign=&quot;top&quot;&gt;Methods  are inherited&lt;/td&gt;   &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;que&quot;&gt;&lt;span class=&quot;queIndex&quot;&gt;5.&lt;/span&gt;&lt;b&gt;How are this() and super() used with  constructors&lt;/b&gt;?&lt;/span&gt; &lt;br /&gt;
&lt;div align=&quot;justify&quot; class=&quot;content&quot;&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;Constructors  use &lt;i&gt;this&lt;/i&gt; to  refer to another constructor in the same class with a different parameter list.&lt;/li&gt;
&lt;li&gt;Constructors  use &lt;i&gt;super&lt;/i&gt; to  invoke the superclass&#39;s constructor. If a constructor uses &lt;i&gt;super&lt;/i&gt;,  it must use it in the first line; otherwise, the compiler will complain. &lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;span class=&quot;que&quot;&gt;&lt;span class=&quot;queIndex&quot;&gt;6.&lt;/span&gt;What are the differences between Class Methods and Instance Methods?&lt;/span&gt;     &lt;br /&gt;
&lt;div align=&quot;justify&quot; class=&quot;content&quot;&gt;&lt;/div&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;5&quot; cellspacing=&quot;5&quot; class=&quot;mytable&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;     &lt;th width=&quot;50%&quot;&gt;&lt;b&gt;Class Methods &lt;/b&gt;&lt;/th&gt;      &lt;th width=&quot;50%&quot;&gt;&lt;b&gt;Instance Methods &lt;/b&gt;&lt;/th&gt;   &lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;     &lt;td&gt;Class  methods are methods which are declared as static. The method can be called  without creating an instance of the  class&lt;/td&gt;     &lt;td&gt;Instance  methods on the other hand require an instance of the  class to exist before they  can be called, so an instance of a class  needs to be created by using the new  keyword.&lt;br /&gt;
Instance methods operate on specific instances of classes.&lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;even&quot;&gt;     &lt;td&gt;Class  methods can only operate on class members and not on instance members as class  methods are  unaware of instance members.&lt;/td&gt;     &lt;td&gt;Instance  methods of the class can also not be called from  within a class method unless  they are being  called on an instance of  that class. &lt;/td&gt;   &lt;/tr&gt;
&lt;tr class=&quot;odd&quot;&gt;      &lt;td&gt;Class  methods are methods which are declared as static. The method can be called  without creating an&amp;nbsp; instance of the  class.&lt;/td&gt;      &lt;td&gt;Instance  methods are not declared as static.&lt;/td&gt;    &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;que&quot;&gt;  &lt;span class=&quot;queIndex&quot;&gt;7.&lt;/span&gt;How are this() and super() used with constructors?&lt;/span&gt; &lt;br /&gt;
&lt;div align=&quot;justify&quot; class=&quot;content&quot;&gt;&lt;/div&gt;&lt;ul&gt;&lt;li&gt;Constructors  use &lt;i&gt;this&lt;/i&gt; to  refer to another constructor in the same class with a different parameter list.&lt;/li&gt;
&lt;li&gt;Constructors  use &lt;i&gt;super&lt;/i&gt; to  invoke the superclass&#39;s  constructor. If a constructor uses super,  it must use it in the first  line; otherwise, the compiler will complain.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;span class=&quot;que&quot;&gt;&lt;span class=&quot;queIndex&quot;&gt;8.&lt;/span&gt;What are Access Specifiers?&lt;/span&gt; &lt;br /&gt;
&lt;div align=&quot;justify&quot; class=&quot;content&quot;&gt;One  of the techniques in object-oriented programming is &lt;i&gt;encapsulation&lt;/i&gt;.   It concerns the hiding of data in a class and making this class  available only  through methods. Java allows you to control access to  classes, methods, and  fields via so-called &lt;i&gt;access specifiers&lt;/i&gt;..&lt;/div&gt;&lt;br /&gt;
&lt;span class=&quot;que&quot;&gt;&lt;span class=&quot;queIndex&quot;&gt;9.&lt;/span&gt;&lt;b&gt;What are Access Specifiers available in Java&lt;/b&gt;?&lt;/span&gt; &lt;br /&gt;
&lt;div align=&quot;justify&quot; class=&quot;content&quot;&gt;Java  offers four access specifiers, listed below in decreasing accessibility:  &lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;Public&lt;/b&gt;- &lt;i&gt;public&lt;/i&gt;  classes, methods, and fields can be accessed from everywhere.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Protected&lt;/b&gt;- &lt;i&gt;protected&lt;/i&gt; methods and fields  can only be accessed within  the same class to which the methods and  fields belong, within its subclasses,  and within classes of the same  package. &lt;/li&gt;
&lt;li&gt;&lt;b&gt;Default(no specifier)- &lt;/b&gt;If you do not set access to  specific level, then  such a class, method, or field will be accessible  from inside the same package  to which the class, method, or field  belongs, but not from outside this  package.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Private&lt;/b&gt;- &lt;i&gt;private&lt;/i&gt; methods and fields can only be accessed within  the same class to which the methods and fields belong. &lt;i&gt;private&lt;/i&gt; methods and fields are not visible within  subclasses and are not inherited by subclasses.&lt;/li&gt;
&lt;/ul&gt;&lt;table border=&quot;1&quot; cellpadding=&quot;5&quot; cellspacing=&quot;5&quot; class=&quot;mytable&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;  &lt;th align=&quot;CENTER&quot;&gt;&amp;nbsp;Situation&amp;nbsp; &lt;/th&gt;    &lt;th align=&quot;CENTER&quot;&gt;&lt;code&gt;&amp;nbsp;public&amp;nbsp;&lt;/code&gt;  &lt;/th&gt;    &lt;th align=&quot;CENTER&quot;&gt;&lt;code&gt;&amp;nbsp;protected&amp;nbsp;&lt;/code&gt;  &lt;/th&gt;    &lt;th align=&quot;CENTER&quot;&gt;&amp;nbsp;default&amp;nbsp; &lt;/th&gt;    &lt;th align=&quot;CENTER&quot;&gt;&lt;code&gt;&amp;nbsp;private&amp;nbsp;&lt;/code&gt;  &lt;/th&gt;  &lt;/tr&gt;
&lt;tr&gt;  &lt;td align=&quot;LEFT&quot;&gt;&amp;nbsp;Accessible to class &lt;br /&gt;
&amp;nbsp;from same package?&amp;nbsp; &lt;/td&gt;    &lt;td align=&quot;CENTER&quot;&gt;yes &lt;/td&gt;    &lt;td align=&quot;CENTER&quot;&gt;yes &lt;/td&gt;    &lt;td align=&quot;CENTER&quot;&gt;yes &lt;/td&gt;    &lt;td align=&quot;CENTER&quot;&gt;no &lt;/td&gt;  &lt;/tr&gt;
&lt;tr&gt;  &lt;td align=&quot;LEFT&quot;&gt;&amp;nbsp;Accessible to class &lt;br /&gt;
&amp;nbsp;from different package?&amp;nbsp; &lt;/td&gt;    &lt;td align=&quot;CENTER&quot;&gt;yes &lt;/td&gt;    &lt;td align=&quot;CENTER&quot;&gt;&amp;nbsp;no, &lt;i&gt;unless it is a subclass&lt;/i&gt;&amp;nbsp; &lt;/td&gt;    &lt;td align=&quot;CENTER&quot;&gt;no &lt;/td&gt;    &lt;td align=&quot;CENTER&quot;&gt;no &lt;/td&gt;  &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;que&quot;&gt;&lt;span class=&quot;queIndex&quot;&gt;10.&lt;/span&gt;&lt;b&gt;What is final modifier&lt;/b&gt;?&lt;/span&gt; &lt;br /&gt;
&lt;div align=&quot;justify&quot; class=&quot;content&quot;&gt;The&amp;nbsp;final&amp;nbsp;modifier keyword makes that  the programmer cannot change the value  anymore. The actual meaning  depends on whether it is applied to a class, a  variable, or a method. &lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;b&gt;&lt;i&gt;final&lt;/i&gt; Classes&lt;/b&gt;- A final class cannot have subclasses.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;final&lt;/i&gt; Variables&lt;/b&gt;- A final variable cannot be changed once it is initialized.&lt;/li&gt;
&lt;li&gt;&lt;b&gt;&lt;i&gt;final&lt;/i&gt; Methods&lt;/b&gt;- A final method cannot be overridden by subclasses. &lt;/li&gt;
&lt;/ul&gt;&lt;span class=&quot;que&quot;&gt;&lt;span class=&quot;queIndex&quot;&gt;11.&lt;/span&gt;&lt;b&gt;What are the uses of final method?&lt;/b&gt;&lt;/span&gt; &lt;br /&gt;
&lt;div align=&quot;justify&quot; class=&quot;content&quot;&gt;There are two reasons for marking a  method as final: &lt;/div&gt;&lt;ul&gt;&lt;li&gt;Disallowing subclasses to change the meaning of  the method.&lt;/li&gt;
&lt;li&gt;Increasing efficiency by allowing the compiler  to turn calls to the method into inline Java code. &lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
&lt;span class=&quot;que&quot;&gt;&lt;span class=&quot;queIndex&quot;&gt;12.&lt;/span&gt;&lt;b&gt;What is static block?&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt; &lt;br /&gt;
&lt;div align=&quot;justify&quot; class=&quot;content&quot;&gt;Static block which exactly executed  exactly once when the class is first  loaded into JVM. Before going to  the main method the static block will execute.&lt;/div&gt;&lt;br /&gt;
&lt;span class=&quot;que&quot;&gt;&lt;span class=&quot;queIndex&quot;&gt;13.&lt;/span&gt;&lt;b&gt;What are static variables?&lt;/b&gt;&lt;/span&gt; &lt;br /&gt;
&lt;div align=&quot;justify&quot; class=&quot;content&quot;&gt;Variables  that have only one copy  per class are known as static variables. They are not  attached to a  particular instance of a class but rather belong to a class as a  whole.  They are declared by using the static keyword as a modifier.&lt;/div&gt;&lt;br /&gt;
&lt;pre class=&quot;mid&quot;&gt;static type  varIdentifier;&lt;/pre&gt;&lt;div align=&quot;justify&quot; class=&quot;content&quot;&gt;where,  the name of the variable is varIdentifier and its data type is specified by  type.&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Note&lt;/b&gt;&lt;/u&gt;: Static  variables that are not explicitly  initialized in the code are automatically  initialized with a default  value. The default value depends on the data type of  the variables.&lt;/div&gt;&lt;br /&gt;
&lt;span class=&quot;que&quot;&gt;&lt;span class=&quot;queIndex&quot;&gt;14.&lt;/span&gt;&lt;b&gt;What is the difference between static and non-static variables?&lt;/b&gt;&lt;br /&gt;
&lt;/span&gt; &lt;br /&gt;
&lt;div align=&quot;justify&quot; class=&quot;content&quot;&gt;A static variable is associated with  the class as a whole rather than with specific instances of a class.  Non-static variables take on unique values with each object instance.&lt;/div&gt;&lt;br /&gt;
&lt;table align=&quot;right&quot; bgcolor=&quot;#fafafa&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tinyblack&quot; style=&quot;border: 0px dashed rgb(173, 210, 226); width: 336px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;  &lt;td&gt;&lt;ins style=&quot;border: none; display: inline-table; height: 280px; margin: 0; padding: 0; position: relative; visibility: visible; width: 336px;&quot;&gt;&lt;/ins&gt;&lt;br /&gt;
&lt;ins id=&quot;aswift_3_anchor&quot; style=&quot;border: none; display: block; height: 280px; margin: 0; padding: 0; position: relative; visibility: visible; width: 336px;&quot;&gt;&lt;/ins&gt;&lt;br /&gt;
&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;&lt;span class=&quot;que&quot;&gt;&lt;span class=&quot;queIndex&quot;&gt;15.&lt;/span&gt;&lt;b&gt;What are static methods?&lt;/b&gt;&lt;/span&gt; &lt;br /&gt;
&lt;div align=&quot;justify&quot; class=&quot;content&quot;&gt;Methods  declared with the keyword  static as modifier are called static methods or class  methods. They are  so called because they affect a class as a whole, not a  particular  instance of the class. Static methods are always invoked without   reference to a particular instance of a class.&lt;br /&gt;
&lt;u&gt;&lt;b&gt;Note&lt;/b&gt;&lt;/u&gt;:The  use of a static method suffers from the following restrictions:   &lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;i&gt;A  static method can only call other static methods.&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;A static method must only access static data.&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;&lt;i&gt;A static method &lt;b&gt;cannot&lt;/b&gt; reference to the current object using keywords &lt;/i&gt;&lt;i&gt;super&lt;/i&gt;&lt;i&gt; or &lt;/i&gt;&lt;i&gt;this&lt;/i&gt;&lt;i&gt;.&lt;/i&gt;&lt;/li&gt;
&lt;/ul&gt;Source: &lt;a href=&quot;http://developersbook.com/&quot;&gt;Developersbook.com&lt;/a&gt; Click &lt;a href=&quot;http://www.developersbook.com/corejava/interview-questions/corejava-interview-questions-faqs-3.php&quot;&gt;here&lt;/a&gt;.</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/7914244211443336009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2011/06/1.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/7914244211443336009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/7914244211443336009'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2011/06/1.html' title='Java Interview Questions - Basic Questions'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5360944016602432340.post-5376389964905541849</id><published>2011-06-22T18:20:00.000-07:00</published><updated>2011-06-22T18:20:35.116-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="interview questions"/><category scheme="http://www.blogger.com/atom/ns#" term="OOP"/><title type='text'>OOP interview questions</title><content type='html'>(&lt;a href=&quot;http://www.developersbook.com/&quot;&gt;www.developersbook.com&lt;/a&gt;) Source: Click &lt;a href=&quot;http://www.developersbook.com/corejava/interview-questions/corejava-interview-questions-faqs.php&quot;&gt;here&lt;/a&gt;.&lt;br /&gt;
1.What are the principle concepts of OOPS?&lt;br /&gt;
&lt;br /&gt;
There are four principle concepts upon which object oriented design and programming rest. They are:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Abstraction&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Polymorphism&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Inheritance&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Encapsulation&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; (i.e. easily remembered as A-PIE). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
2.What is Abstraction?&lt;br /&gt;
&lt;br /&gt;
Abstraction refers to the act of representing essential features without including the background details or explanations.&lt;br /&gt;
&lt;br /&gt;
3.What is Encapsulation?&lt;br /&gt;
&lt;br /&gt;
Encapsulation is a technique used for hiding the properties and behaviors of an object and allowing outside access only as appropriate. It prevents other objects from directly altering or accessing the properties or methods of the encapsulated object.&lt;br /&gt;
&lt;br /&gt;
4.What is the difference between abstraction and encapsulation?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Abstraction focuses on the outside view of an object (i.e. the interface) Encapsulation (information hiding) prevents clients from seeing it’s inside view, where the behavior of the abstraction is implemented.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Abstraction solves the problem in the design side while Encapsulation is the Implementation.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Encapsulation is the deliverables of Abstraction. Encapsulation barely talks about grouping up your abstraction to suit the developer needs. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
5.What is Inheritance?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Inheritance is the process by which objects of one class acquire the properties of objects of another class.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; A class that is inherited is called a superclass.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; The class that does the inheriting is called a subclass.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Inheritance is done by using the keyword extends.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; The two most common reasons to use inheritance are:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; To promote code reuse&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; To use polymorphism&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
6.What is Polymorphism?&lt;br /&gt;
&lt;br /&gt;
Polymorphism is briefly described as &quot;one interface, many implementations.&quot; Polymorphism is a characteristic of being able to assign a different meaning or usage to something in different contexts - specifically, to allow an entity such as a variable, a function, or an object to have more than one form.&lt;br /&gt;
&lt;br /&gt;
7.How does Java implement polymorphism?&lt;br /&gt;
&lt;br /&gt;
(Inheritance, Overloading and Overriding are used to achieve Polymorphism in java).&lt;br /&gt;
Polymorphism manifests itself in Java in the form of multiple methods having the same name.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; In some cases, multiple methods have the same name, but different formal argument lists (overloaded methods).&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; In other cases, multiple methods have the same name, same return type, and same formal argument list (overridden methods). &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
8.Explain the different forms of Polymorphism.&lt;br /&gt;
&lt;br /&gt;
There are two types of polymorphism one is Compile time polymorphism and the other is run time polymorphism. Compile time polymorphism is method overloading. Runtime time polymorphism is done using inheritance and interface.&lt;br /&gt;
Note: From a practical programming viewpoint, polymorphism manifests itself in three distinct forms in Java:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Method overloading&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Method overriding through inheritance&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Method overriding through the Java interface&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
9.What is runtime polymorphism or dynamic method dispatch?&lt;br /&gt;
&lt;br /&gt;
In Java, runtime polymorphism or dynamic method dispatch is a process in which a call to an overridden method is resolved at runtime rather than at compile-time. In this process, an overridden method is called through the reference variable of a superclass. The determination of the method to be called is based on the object being referred to by the reference variable.&lt;br /&gt;
&lt;br /&gt;
10.What is Dynamic Binding?&lt;br /&gt;
&lt;br /&gt;
Binding refers to the linking of a procedure call to the code to be executed in response to the call. Dynamic binding (also known as late binding) means that the code associated with a given procedure call is not known until the time of the call at run-time. It is associated with polymorphism and inheritance.&lt;br /&gt;
&lt;br /&gt;
11.What is method overloading?&lt;br /&gt;
&lt;br /&gt;
Method Overloading means to have two or more methods with same name in the same class with different arguments. The benefit of method overloading is that it allows you to implement methods that support the same semantic operation but differ by argument number or type.&lt;br /&gt;
Note:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Overloaded methods MUST change the argument list&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Overloaded methods CAN change the return type&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Overloaded methods CAN change the access modifier&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Overloaded methods CAN declare new or broader checked exceptions&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; A method can be overloaded in the same class or in a subclass&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
12.What is method overriding?&lt;br /&gt;
&lt;br /&gt;
Method overriding occurs when sub class declares a method that has the same type arguments as a method declared by one of its superclass. The key benefit of overriding is the ability to define behavior that’s specific to a particular subclass type.&lt;br /&gt;
Note:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; The overriding method cannot have a more restrictive access modifier than the method being overridden (Ex: You can’t override a method marked public and make it protected).&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; You cannot override a method marked final&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; You cannot override a method marked static&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 13.What are the differences between method overloading and method overriding?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;Overloaded Method &amp;nbsp;&amp;nbsp; &amp;nbsp;Overridden Method&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Arguments &amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Must change&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Must not change&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Return type&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Can change&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Can’t change except for covariant returns&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Exceptions&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Can change&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Can reduce or eliminate. Must not throw new or broader checked exceptions&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Access&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Can change&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Must not make more restrictive (can be less restrictive)&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Invocation&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Reference type determines which overloaded version is selected. Happens at compile time.&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Object type determines which method is selected. Happens at runtime.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 14.Can overloaded methods be override too?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Yes, derived classes still can override the overloaded methods. Polymorphism can still happen. Compiler will not binding the method calls since it is overloaded, because it might be overridden now or in the future.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 15.Is it possible to override the main method?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; NO, because main is a static method. A static method can&#39;t be overridden in Java.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 16.How to invoke a superclass version of an Overridden method?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; To invoke a superclass method that has been overridden in a subclass, you must either call the method directly through a superclass instance, or use the super prefix in the subclass itself. From the point of the view of the subclass, the super prefix provides an explicit reference to the superclass&#39; implementation of the method.&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; // From subclass&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;super.overriddenMethod();&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; 17.What is super?&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; super is a keyword which is used to access the method or member variables from the superclass. If a method hides one of the member variables in its superclass, the method can refer to the hidden variable through the use of the super keyword. In the same way, if a method overrides one of the methods in its superclass, the method can invoke the overridden method through the use of the super keyword.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Note:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; You can only go back one level.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; In the constructor, if you use super(), it must be the very first code, and you cannot access any this.xxx variables or methods to compute its parameters.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
18.How do you prevent a method from being overridden?&lt;br /&gt;
&lt;br /&gt;
To prevent a specific method from being overridden in a subclass, use the final modifier on the method declaration, which means &quot;this is the final implementation of this method&quot;, the end of its inheritance hierarchy.&lt;br /&gt;
&lt;br /&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; public final void exampleMethod() {&lt;br /&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; Method statements&lt;br /&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; }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
19.What is an Interface?&lt;br /&gt;
&lt;br /&gt;
An interface is a description of a set of methods that conforming implementing classes must have.&lt;br /&gt;
Note:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; You can’t mark an interface as final.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Interface variables must be static.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; An Interface cannot extend anything but another interfaces.&lt;br /&gt;
&lt;br /&gt;
20.Can we instantiate an interface?&lt;br /&gt;
&lt;br /&gt;
You can’t instantiate an interface directly, but you can instantiate a class that implements an interface.&lt;br /&gt;
&lt;br /&gt;
21.Can we create an object for an interface?&lt;br /&gt;
&lt;br /&gt;
Yes, it is always necessary to create an object implementation for an interface. Interfaces cannot be instantiated in their own right, so you must write a class that implements the interface and fulfill all the methods defined in it.&lt;br /&gt;
&lt;br /&gt;
22.Do interfaces have member variables?&lt;br /&gt;
&lt;br /&gt;
Interfaces may have member variables, but these are implicitly public, static, and final- in other words, interfaces can declare only constants, not instance variables that are available to all implementations and may be used as key references for method arguments for example.&lt;br /&gt;
&lt;br /&gt;
23.What modifiers are allowed for methods in an Interface?&lt;br /&gt;
&lt;br /&gt;
Only public and abstract modifiers are allowed for methods in interfaces.&lt;br /&gt;
&lt;br /&gt;
24.What is a marker interface?&lt;br /&gt;
&lt;br /&gt;
Marker interfaces are those which do not declare any required methods, but signify their compatibility with certain operations. The java.io.Serializable interface and Cloneable are typical marker interfaces. These do not contain any methods, but classes must implement this interface in order to be serialized and de-serialized.&lt;br /&gt;
&lt;br /&gt;
25.What is an abstract class?&lt;br /&gt;
&lt;br /&gt;
Abstract classes are classes that contain one or more abstract methods. An abstract method is a method that is declared, but contains no implementation.&lt;br /&gt;
Note:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; If even a single method is abstract, the whole class must be declared abstract.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Abstract classes may not be instantiated, and require subclasses to provide implementations for the abstract methods.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; You can’t mark a class as both abstract and final.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
26.Can we instantiate an abstract class?&lt;br /&gt;
&lt;br /&gt;
An abstract class can never be instantiated. Its sole purpose is to be extended (subclassed).&lt;br /&gt;
&lt;br /&gt;
27.What are the differences between Interface and Abstract class?&lt;br /&gt;
&lt;br /&gt;
Abstract Class &amp;nbsp;&amp;nbsp; &amp;nbsp;Interfaces&lt;br /&gt;
An abstract class can provide complete, default code and/or just the details that have to be overridden. &amp;nbsp;&amp;nbsp; &amp;nbsp;An interface cannot provide any code at all,just the signature.&lt;br /&gt;
In case of abstract class, a class may extend only one abstract class. &amp;nbsp;&amp;nbsp; &amp;nbsp;A Class may implement several interfaces.&lt;br /&gt;
An abstract class can have non-abstract methods. &amp;nbsp;&amp;nbsp; &amp;nbsp;All methods of an Interface are abstract.&lt;br /&gt;
An abstract class can have instance variables. &amp;nbsp;&amp;nbsp; &amp;nbsp;An Interface cannot have instance variables.&lt;br /&gt;
An abstract class can have any visibility: public, private, protected. &amp;nbsp;&amp;nbsp; &amp;nbsp;An Interface visibility must be public (or) none.&lt;br /&gt;
If we add a new method to an abstract class then we have the option of providing default implementation and therefore all the existing code might work properly. &amp;nbsp;&amp;nbsp; &amp;nbsp;If we add a new method to an Interface then we have to track down all the implementations of the interface and define implementation for the new method.&lt;br /&gt;
An abstract class can contain constructors . &amp;nbsp;&amp;nbsp; &amp;nbsp;An Interface cannot contain constructors .&lt;br /&gt;
Abstract classes are fast. &amp;nbsp;&amp;nbsp; &amp;nbsp;Interfaces are slow as it requires extra indirection to find corresponding method in the actual class.&lt;br /&gt;
&lt;br /&gt;
28.When should I use abstract classes and when should I use interfaces?&lt;br /&gt;
&lt;br /&gt;
Use Interfaces when…&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; You see that something in your design will change frequently.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; If various implementations only share method signatures then it is better to use Interfaces.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; you need some classes to use some methods which you don&#39;t want to be included in the class, then you go for the interface, which makes it easy to just implement and make use of the methods defined in the interface.&lt;br /&gt;
&lt;br /&gt;
Use Abstract Class when…&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; If various implementations are of the same kind and use common behavior or status then abstract class is better to use.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; When you want to provide a generalized form of abstraction and leave the implementation task with the inheriting subclass.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Abstract classes are an excellent way to create planned inheritance hierarchies. They&#39;re also a good choice for nonleaf classes in class hierarchies.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
29.When you declare a method as abstract, can other nonabstract methods access it?&lt;br /&gt;
&lt;br /&gt;
Yes, other nonabstract methods can access a method that you declare as abstract.&lt;br /&gt;
&lt;br /&gt;
30.Can there be an abstract class with no abstract methods in it?&lt;br /&gt;
&lt;br /&gt;
Yes, there can be an abstract class without abstract methods.</content><link rel='replies' type='application/atom+xml' href='http://codeinterview.blogspot.com/feeds/5376389964905541849/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://codeinterview.blogspot.com/2011/06/oop-interview-questions.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/5376389964905541849'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/5360944016602432340/posts/default/5376389964905541849'/><link rel='alternate' type='text/html' href='http://codeinterview.blogspot.com/2011/06/oop-interview-questions.html' title='OOP interview questions'/><author><name>Chev</name><uri>http://www.blogger.com/profile/01567672829178182017</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><thr:total>0</thr:total></entry></feed>