<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SCJP Certification &#187; constructor</title>
	<atom:link href="http://www.scjp-certification.com/tag/constructor/feed" rel="self" type="application/rss+xml" />
	<link>http://www.scjp-certification.com</link>
	<description>Sun Certified Java Programmer Certification exam essentials</description>
	<lastBuildDate>Fri, 30 Sep 2011 05:54:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>What are the conventions for writing constructors?</title>
		<link>http://www.scjp-certification.com/what-are-the-conventions-for-writing-constructors.html</link>
		<comments>http://www.scjp-certification.com/what-are-the-conventions-for-writing-constructors.html#comments</comments>
		<pubDate>Wed, 02 Dec 2009 11:45:36 +0000</pubDate>
		<dc:creator>Daisy Williams</dc:creator>
				<category><![CDATA[Java Facts]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[exam guide]]></category>
		<category><![CDATA[strictf]]></category>
		<category><![CDATA[study guide]]></category>
		<category><![CDATA[synchronized]]></category>

		<guid isPermaLink="false">http://www.scjp-certification.com/?p=457</guid>
		<description><![CDATA[A constructor provides a convenient way to initialize a newly created object at the time of its creation. It is...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.scjp-certification.com%2Fwhat-are-the-conventions-for-writing-constructors.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.scjp-certification.com%2Fwhat-are-the-conventions-for-writing-constructors.html&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>A constructor provides a convenient way to initialize a newly created object at the time of its creation. It is defined for a class and it is called automatically immediately after the creation of a new object, but before the new operator completes. All Although constructors look the same as methods, they are written by using the following conventions:
<ol>
<li>A constructor is always given the name of the class in which it is defined.</li>
<li>A constructor is always written without an explicit return type, not even void. This is because the implicit return type of a class constructor is the class itself.</li>
<li> Only accessibility modifiers can be used to declared a constructor. Unlike methods, a constructor cannot be declared as abstract, static, final, native, strictfp, or synchronized.</li>
</ol>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.scjp-certification.com%2Fwhat-are-the-conventions-for-writing-constructors.html&amp;title=What%20are%20the%20conventions%20for%20writing%20constructors%3F"><img src="http://www.scjp-certification.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.scjp-certification.com/what-are-the-conventions-for-writing-constructors.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Constructors</title>
		<link>http://www.scjp-certification.com/constructors.html</link>
		<comments>http://www.scjp-certification.com/constructors.html#comments</comments>
		<pubDate>Tue, 17 Nov 2009 11:47:54 +0000</pubDate>
		<dc:creator>Daisy Williams</dc:creator>
				<category><![CDATA[Java Questions]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[exam guide]]></category>
		<category><![CDATA[free question]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[overriden]]></category>
		<category><![CDATA[question]]></category>
		<category><![CDATA[study guide]]></category>
		<category><![CDATA[super]]></category>

		<guid isPermaLink="false">http://www.scjp-certification.com/?p=418</guid>
		<description><![CDATA[If a class Student creates two student objects. Which of the following statements are true about its constructors? A: The...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.scjp-certification.com%2Fconstructors.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.scjp-certification.com%2Fconstructors.html&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>If a class Student creates two student objects.  Which of the following statements are true about its constructors?</p>
<p> A: The compiler can call to super() in any constructor that has a call to this().<br />
 B: If a constructor is not declared in the code, a default constructor will be automatically generated by the compiler.<br />
 C: Constructors can be overridden.<br />
 D: The compiler cannot call to super() in any constructor that has a call to this()</p>
<p>ANSWERS: </p>
<p>If a  <a href="http://www.scjp-certification.com/what-is-a-constructor-2.html">constructor</a> has a call to this(), the compiler will know that the constructor is not using the call to super(). A constructor can never have both a call to super() and a call to this() because one of these will be used as the first statement in the constructor. The compiler will not put a call to super() that is using a call to this().</p>
<p>If a constructor is not declared in the code, a default constructor will be automatically generated by the compiler. A constructor without any parameters is known as a default constructor. When a class is defined without any constructor, the Java compiler provides an implicit default constructor. </p>
<p>When the implicit default constructor of a class is invoked, it implicitly calls the no parameter constructor in the superclass. This action taken by a default constructor ensures that the inherited state of the object is initialized properly. In addition, it initializes all the instance variables in the object to the default value depending on their data type.</p>
<p>The default constructor of a class has the same access modifier with which the class has been declared. For example, the default constructor of a public class is implicitly given the public access. The default constructor of a protected class is implicitly given the protected access. The default constructor of a private class is implicitly given the private access. Otherwise, the default constructor has the default access implied by no access modifier.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.scjp-certification.com%2Fconstructors.html&amp;title=Constructors"><img src="http://www.scjp-certification.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.scjp-certification.com/constructors.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What will be the ouput of the following program?</title>
		<link>http://www.scjp-certification.com/what-will-be-the-ouput-of-the-following-program.html</link>
		<comments>http://www.scjp-certification.com/what-will-be-the-ouput-of-the-following-program.html#comments</comments>
		<pubDate>Tue, 10 Nov 2009 12:18:58 +0000</pubDate>
		<dc:creator>Daisy Williams</dc:creator>
				<category><![CDATA[Java Facts]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[exam]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[static]]></category>

		<guid isPermaLink="false">http://www.scjp-certification.com/?p=397</guid>
		<description><![CDATA[class box { int height; int weight; box( int a, int b) { height=a; weight=b; System.out.println(height); System.out.println(weight); } } class...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.scjp-certification.com%2Fwhat-will-be-the-ouput-of-the-following-program.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.scjp-certification.com%2Fwhat-will-be-the-ouput-of-the-following-program.html&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>class box<br />
 {<br />
    int height;<br />
    int weight;</p>
<p>     box( int a, int b)<br />
       {<br />
         height=a;<br />
         weight=b;<br />
          System.out.println(height);<br />
          System.out.println(weight);<br />
        }</p>
<p> }</p>
<p>class Box2<br />
 {<br />
   public static void main(String args[])<br />
     {<br />
       Box2 b2=new box();<br />
     }<br />
  }</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.scjp-certification.com%2Fwhat-will-be-the-ouput-of-the-following-program.html&amp;title=What%20will%20be%20the%20ouput%20of%20the%20following%20program%3F"><img src="http://www.scjp-certification.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.scjp-certification.com/what-will-be-the-ouput-of-the-following-program.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What is a constructor?</title>
		<link>http://www.scjp-certification.com/what-is-a-constructor-2.html</link>
		<comments>http://www.scjp-certification.com/what-is-a-constructor-2.html#comments</comments>
		<pubDate>Mon, 02 Nov 2009 12:04:35 +0000</pubDate>
		<dc:creator>Daisy Williams</dc:creator>
				<category><![CDATA[Java Facts]]></category>
		<category><![CDATA[constructor]]></category>
		<category><![CDATA[default]]></category>
		<category><![CDATA[final]]></category>
		<category><![CDATA[initialize]]></category>
		<category><![CDATA[object]]></category>

		<guid isPermaLink="false">http://www.scjp-certification.com/?p=343</guid>
		<description><![CDATA[A constructor provides a convenient way to initialize a newly created object at the time of its creation. A constructor...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.scjp-certification.com%2Fwhat-is-a-constructor-2.html"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.scjp-certification.com%2Fwhat-is-a-constructor-2.html&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>A constructor provides a convenient way to initialize a newly created object at the time of its creation. A constructor is automatically called emmediately after the creation of a new object, but before the new operator completes. All Java classes must have at least one constructor, either explicitly declared in the class or an implicit default constructor. They are typically used to create an object that is an instance of a class. It is written by using the following general syntax:</p>
<p><strong>[access modifier] class name([formal parameter list]) [throws clause] {<br />
   // Body of the constructor<br />
}</strong></p>
<p>where, the elements within square brackets are optional. </p>
<p>The following rules are followed before writing a constructor for a class:
<ol>
<li>It uses the name of the class in which it is defined.</li>
<li>A constructor is always written without an explicit return type, not even void. This is because the implicit return type of a class constructor is the class itself.</li>
<li>Only accessibility modifiers can be used to declared a constructor. Unlike methods, a constructor cannot be declared as abstract, static, final, native, strictfp, or synchronized.</li>
</ol>
<p>The following is an example of a constructor:</p>
<p><strong>class Book{<br />
   String name;<br />
   String author;<br />
    Rectangle(String str1, String str2){<br />
       // more code<br />
   }<br />
}</strong>  </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.scjp-certification.com%2Fwhat-is-a-constructor-2.html&amp;title=What%20is%20a%20constructor%3F"><img src="http://www.scjp-certification.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.scjp-certification.com/what-is-a-constructor-2.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

