• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to re-factor this code by method extraction?  RSS feed

 
Robert Redman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is one of my my assignment question.

re-factor the code below by method extraction
void drawFigure(){
//head statement
System.out.println ("***");
System.out.println ("***");
System.out.println ("***");

//draw body
System.out.println ("***");
System.out.println ("***");
System.out.println ("***");

}


I should use get and set method for this.
So I've tried:

public class method{

public String head;

public void setHead() {
System.out.print ("*");
}

public String getHead(){
return head;
}

public static void main (String arg[]){


}
}


But whatever I put in public static void main it does not work.
How to make it work?
 
Robert Redman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but I do not see set and get in that link
 
Les Morgan
Rancher
Posts: 768
19
C++ Java MySQL Database Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert Redman wrote:
But whatever I put in public static void main it does not work.
How to make it work?


main is an entry point and is static, so it exists at runtime, but the Class has not been instantiated, so the rest of the Class is not available. In order to get the rest of the Class, you have to instantiate to get the resulting object.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!