Learning Java 3th

Continue to the Learning Java 2th, here we are going to talk about the differences between Java and C#.

1. Constructor

    1) static constructor: java allows multi static constructors, but in C#, static constructor can be only one.

/*
*java code
*/
public class Test{
     static{
          //static operations
     }
     
     static{
          //static operations
     }      
}
/*
*C# code
*/
public class Test
{
     static Test()
     {
          
     }
}

    2) normal constructor

/*
*java code
*/
public class Test{
     public Test(){
     }
      
     public Test(int i){
           //If you provide the constructor with parameter, then you have to provide the none-parameters constructor, otherwise the compiler will 
       //not pass
} public Test(int i, String str){ this(i); //If you have to excute a constructor, you have to add it at first statement,and if you don't provide any constructor,it will
//automatically add the default constructor Test()
} } 
/*
*C# code
*/
public class Test
{
     public Test(int i)
     {

     }
      
     public Test(int i,String str):this(i)
     {
         //It's no doubt that C# is more elegant in syntax
     }
}

2. Method

3. Object

 

The Object of Java also has method reference to thread.

posted @ 2013-11-17 11:22  teroy  阅读(139)  评论(0)    收藏  举报