{"id":350,"date":"2007-10-21T00:00:00","date_gmt":"2007-10-21T00:00:00","guid":{"rendered":"http:\/\/www.strongd.net\/?p=350"},"modified":"2007-10-21T00:00:00","modified_gmt":"2007-10-21T00:00:00","slug":"Generating Undeclared Methods","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=350","title":{"rendered":"Generating Undeclared Methods"},"content":{"rendered":"<p><P>Eclipse has many features that make the job of a programmer easy. Here a simple project is created and will use few of those features to demonstrate how easy programming can be using Eclipse. Most of the new programmers, ignore these and prefer to code everything themselves which is time consuming.<\/P><br \/>\n<P><A id=more-105><\/A><\/P><br \/>\n<OL><br \/>\n<LI>First creating a package: really simple. Right click the project name and click \u201c New \u201d &#8211; &gt; \u201c Package\u201d . Name it as \u201ccar\u201d .<\/LI><br \/>\n<P><IMG height=400 src=\"http:\/\/www.eclipse-blog.org\/wp-content\/uploads\/2007\/05\/package.PNG\" width=432><\/P><br \/>\n<LI>Creating a class in it named \u201c Car \u201d and defined 2 private attributes namely \u201c doors \u201d , \u201c seats \u201d . Now generate getters\/setters for that. Eclipse can generate those for us. In the Source menu, click \u201c Generate getters and setters \u201d .<\/LI><br \/>\n<P><IMG height=533 src=\"http:\/\/www.eclipse-blog.org\/wp-content\/uploads\/2007\/05\/getters-setters.PNG\" width=430><BR><IMG height=533 src=\"http:\/\/www.eclipse-blog.org\/wp-content\/uploads\/2007\/05\/main.PNG\" width=430><\/P><br \/>\n<LI>Now make another class in the same package named \u201c Honda \u201d. Create a \u201c main \u201d method in this class. Eclipse will generate \u201c main \u201d method once you check the \u201c generate main method \u201d checkbox while creating the class.<\/LI><br \/>\n<LI>Also to make Car class to be the superclass for \u201c Honda \u201d class. Click \u201c Browse \u201d button against superclass field of the class declaration window. As \u201c Car \u201d class is under package \u201c cars \u201d, parent class for Honda will be \u201c cars.Car \u201d.<\/LI><br \/>\n<P><IMG height=533 src=\"http:\/\/www.eclipse-blog.org\/wp-content\/uploads\/2007\/05\/superclass.PNG\" width=430><\/P><\/OL><br \/>\n<P>Eclipse will generate the following code:<\/P><br \/>\n<DIV class=wp_syntax><br \/>\n<DIV class=code><PRE class=java><SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">package<\/SPAN> cars;public <SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">class<\/SPAN> Honda <SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">extends<\/SPAN> Car <SPAN style=\"COLOR: rgb(102,204,102)\">{<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"COLOR: rgb(128,128,128); FONT-STYLE: italic\">\/**<br \/>\n&nbsp;<br \/>\n* @param args<br \/>\n&nbsp;<br \/>\n*\/<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">public<\/SPAN> <SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">static<\/SPAN> <SPAN style=\"COLOR: rgb(153,51,51)\">void<\/SPAN> main<SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(170,170,221)\">String<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">[<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">]<\/SPAN> args<SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN> <SPAN style=\"COLOR: rgb(102,204,102)\">{<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"COLOR: rgb(128,128,128); FONT-STYLE: italic\">\/\/ TODO Auto-generated method stub<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"COLOR: rgb(102,204,102)\">}<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"COLOR: rgb(102,204,102)\">}<\/SPAN><\/PRE><\/DIV><\/DIV><br \/>\n<P>In class Honda, following lines of code are added.<\/P><br \/>\n<DIV class=wp_syntax><br \/>\n<DIV class=code><PRE class=java>\tCar car1 = <SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">new<\/SPAN> Honda<SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN>; car1.<SPAN style=\"COLOR: rgb(0,102,0)\">setSeats<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"COLOR: rgb(204,102,204)\">4<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN>;<br \/>\n&nbsp;<br \/>\ncar1.<SPAN style=\"COLOR: rgb(0,102,0)\">setDoors<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"COLOR: rgb(204,102,204)\">2<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN>;<br \/>\n&nbsp;<br \/>\n<SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(170,170,221)\">System<\/SPAN>.<SPAN style=\"COLOR: rgb(0,102,0)\">out<\/SPAN>.<SPAN style=\"COLOR: rgb(0,102,0)\">println<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN>car1.<SPAN style=\"COLOR: rgb(0,102,0)\">calcNum<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN>;<\/PRE><\/DIV><\/DIV><br \/>\n<P>\u201c car1.calcNum() \u201d shows error as this method is not declared in the class Car. One way is to go back to class Car and declare the method. Simple way is to click the red cross on the left of the problem line and Eclipse will give you the options for automatically generating the required method in the required class. After generating the required method, Write code according to the requirement in the generated method.<\/P><br \/>\n<P><IMG src=\"http:\/\/www.eclipse-blog.org\/wp-content\/uploads\/2007\/05\/autogen.PNG\"><\/P><br \/>\n<P>Review the code:<\/P><br \/>\n<DIV class=wp_syntax><br \/>\n<DIV class=code><PRE class=java><SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">package<\/SPAN> cars;public <SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">class<\/SPAN> Car <SPAN style=\"COLOR: rgb(102,204,102)\">{<\/SPAN><SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">private<\/SPAN> <SPAN style=\"COLOR: rgb(153,51,51)\">int<\/SPAN> doors;private <SPAN style=\"COLOR: rgb(153,51,51)\">int<\/SPAN> seats;<br \/>\n&nbsp;<br \/>\n<SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">public<\/SPAN> <SPAN style=\"COLOR: rgb(153,51,51)\">int<\/SPAN> getDoors<SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN> <SPAN style=\"COLOR: rgb(102,204,102)\">{<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">return<\/SPAN> doors;<br \/>\n&nbsp;<br \/>\n<SPAN style=\"COLOR: rgb(102,204,102)\">}<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">public<\/SPAN> <SPAN style=\"COLOR: rgb(153,51,51)\">void<\/SPAN> setDoors<SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"COLOR: rgb(153,51,51)\">int<\/SPAN> doors<SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN> <SPAN style=\"COLOR: rgb(102,204,102)\">{<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">this<\/SPAN>.<SPAN style=\"COLOR: rgb(0,102,0)\">doors<\/SPAN> = doors;<br \/>\n&nbsp;<br \/>\n<SPAN style=\"COLOR: rgb(102,204,102)\">}<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">public<\/SPAN> <SPAN style=\"COLOR: rgb(153,51,51)\">int<\/SPAN> getSeats<SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN> <SPAN style=\"COLOR: rgb(102,204,102)\">{<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">return<\/SPAN> seats;<br \/>\n&nbsp;<br \/>\n<SPAN style=\"COLOR: rgb(102,204,102)\">}<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">public<\/SPAN> <SPAN style=\"COLOR: rgb(153,51,51)\">void<\/SPAN> setSeats<SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"COLOR: rgb(153,51,51)\">int<\/SPAN> seats<SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN> <SPAN style=\"COLOR: rgb(102,204,102)\">{<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">this<\/SPAN>.<SPAN style=\"COLOR: rgb(0,102,0)\">seats<\/SPAN> = seats;<br \/>\n&nbsp;<br \/>\n<SPAN style=\"COLOR: rgb(102,204,102)\">}<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">public<\/SPAN> <SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(170,170,221)\">Object<\/SPAN> calcNum<SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN> <SPAN style=\"COLOR: rgb(102,204,102)\">{<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">return<\/SPAN> <SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">this<\/SPAN>.<SPAN style=\"COLOR: rgb(0,102,0)\">getDoors<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN> * <SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">this<\/SPAN>.<SPAN style=\"COLOR: rgb(0,102,0)\">getSeats<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN>;<br \/>\n&nbsp;<br \/>\n<SPAN style=\"COLOR: rgb(102,204,102)\">}<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"COLOR: rgb(102,204,102)\">}<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">package<\/SPAN> cars;<br \/>\n&nbsp;<br \/>\n<SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">public<\/SPAN> <SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">class<\/SPAN> Honda <SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">extends<\/SPAN> Car <SPAN style=\"COLOR: rgb(102,204,102)\">{<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">public<\/SPAN> <SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">static<\/SPAN> <SPAN style=\"COLOR: rgb(153,51,51)\">void<\/SPAN> main<SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(170,170,221)\">String<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">[<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">]<\/SPAN> args<SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN> <SPAN style=\"COLOR: rgb(102,204,102)\">{<\/SPAN><br \/>\n&nbsp;<br \/>\nCar car1 = <SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(0,0,0)\">new<\/SPAN> Honda<SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN>;<br \/>\n&nbsp;<br \/>\ncar1.<SPAN style=\"COLOR: rgb(0,102,0)\">setSeats<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"COLOR: rgb(204,102,204)\">4<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN>;<br \/>\n&nbsp;<br \/>\ncar1.<SPAN style=\"COLOR: rgb(0,102,0)\">setDoors<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"COLOR: rgb(204,102,204)\">2<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN>;<br \/>\n&nbsp;<br \/>\n<SPAN style=\"FONT-WEIGHT: bold; COLOR: rgb(170,170,221)\">System<\/SPAN>.<SPAN style=\"COLOR: rgb(0,102,0)\">out<\/SPAN>.<SPAN style=\"COLOR: rgb(0,102,0)\">println<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN>car1.<SPAN style=\"COLOR: rgb(0,102,0)\">calcNum<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">(<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN><SPAN style=\"COLOR: rgb(102,204,102)\">)<\/SPAN>;<br \/>\n&nbsp;<br \/>\n<SPAN style=\"COLOR: rgb(102,204,102)\">}<\/SPAN><br \/>\n&nbsp;<br \/>\n<SPAN style=\"COLOR: rgb(102,204,102)\">}<\/SPAN><\/PRE><\/DIV><\/DIV><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Eclipse has many features that make the job of a programmer easy. Here a simple project is created and will use few of those features to demonstrate how easy programming can be using Eclipse. Most of the new programmers, ignore these and prefer to code everything themselves which is time consuming. First creating a package: &hellip; <a href=\"https:\/\/www.strongd.net\/?p=350\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Generating Undeclared Methods<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-350","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/350","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=350"}],"version-history":[{"count":0,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/350\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=350"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=350"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=350"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}