Joined: Tue Mar 27, 2007 10:55 pm Posts: 2103 Location: Earth Has thanked: 39 time Have thanks: 56 time
Have braces block inside your class: There are two types of braces you have first one is the regular braces, the code inside these blocks in called when you create an instance from the class. The second type is the static braces blocks ,the code inside these blocks is called when the class is loaded .
Code:
interface shape {
public void draw(); } public class square implements shape {
{ System.out.println("Am a shape"); } static { System.out.println("square is implementing the shape . "); } public void draw(){ System.out.println("Drawing a shape !!! "); }
public static void main(String args[]) { new square().draw(); } }
Here is the output :
Code:
square is implementing the shape . Am a shape Drawing a shape !!!
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )