SCJP 310-055 Study Tour

Published: 10th March 2011
Views: N/A
Ask About This Article Print Republish This Article


Java programming for out friends, understand the Java compiler and Jvm is very helpful. Here is my little sense, be regarded as the Java compiler and Jvm little understanding of the small temper it.


 class Shuiguo{


  void display(){


    System.out.println("shuiguo");


  }


 }



 class Pingguo extends shuiguo{


  void display(){


    System.out.println("pingguo");


  }


void showtype(){


System.out.println("I AM AN Apple");


}


 }


 


 public class Test{


   public static void main(String[] args){


     Shuiguo sg1 = new Shuiguo();


     Pingguo pg = new Pingguo();


     Shuiguo sg2 = new Pingguo();


     sg1.display();


     pg.display();


     sg2.display();




  }


 }


1. Java compiler as an impatient person, do not stop and look at the issue.


sg1.display (); and pg.display (); is detected when the two statements, Java compiler, first check the type of reference variable, namely Shuiguo and Pingguo, and then see whether the corresponding classes are called members of the method. The results showed that: Shuiguo class inside display (); this method; while Pingguo also display (); approaches to meet their own requirements, which are detected by the statement.



2. Please note that when testing sg2.display (); happen when the details. The compiler is Shuiguo sg2 type detected, and then view the member method below Shuiguo display (); test passed. In other words, sg2 really call display (); this method is who, the compiler is not to ignore, he is only concerned about the type of reference variable if the following is called the reference member variable.



3. In the main method to add a few lines of code are as follows




Shuiguo sg2 = new Shuiguo ();


Pingguo pg3 = (Pingguo) sg2;


pg3.showtype ();


In accordance with the earlier reasoning, the three lines of code is correct. Through their own testing and found that indeed can be compiled and no errors at compile time. But running Shique throws an exception, that there is no pg3 following showtype (); this method.



Test can be resolved through 310-055 friends such code, I got SUN certified to 1 month, there are many of them can not be resolved, some still need the help of friends, get friends SCJP certification basic than I am proficient. Last I heard Testinside good learning materials, my friend bought, but also successfully passed the exam, it is really amazing.




This article is free for republishing
Source: http://ludy1987.articlealley.com/scjp-310055-study-tour-2105159.html


Report this article Ask About This Article Print Republish This Article


Loading...
More to Explore
 


Ask a Professional Online Now
27 Experts are Online. Ask a Question, Get an Answer ASAP.
Type your question here...
Optional:
Select...