Java result output.

Source: Internet
Author: User

[Java]
What is the code output result? Why is this result?
Code 1
Public class ParentTest {
Public ParentTest (){
System. out. println ("Parent Constructor invoked ");
}
Static {
System. out. println ("parent static invoked ");
}

{
System. out. println ("parent invoked ");
}
}
Public class ChildrenTest extends ParentTest {
Public ChildrenTest (){
System. out. println ("Children Constructor invoked ");
}
Static {
System. out. println ("Children static invoked ");
}

{
System. out. println ("Children invoked ");
}
Public static void main (String [] args ){
New ChildrenTest ();
}
}
Code 2: true or false
Public class MyTest1 {
Private String str;
Public MyTest1 (String str ){
This. str = str;
}
Public static void main (String [] args ){
MyTest1 m1 = new MyTest1 ("hello ");
MyTest 1 m2 = new MyTest1 ("hello ");
System. out. println (m1.equals (m2 ));
}
}
Code 3: true or false
Public class MyTest1 {
Public static void main (String [] args ){
System. out. println (Integer. valueOf (323) = Integer. valueOf (323 ));
System. out. println (Integer. valueOf (23) = Integer. valueOf (23 ));
}
}
Code 4:
Public class MyTest1 {
Private static int;
Public MyTest1 (){
System. out. println ("a =" + (++ ));
}
Public void test (){
Int a = 5;
System. out. println ("a =" + );
}
Public void test2 (){
A = 5;
System. out. println ("a =" + );
}
Public static void main (String [] args ){
New MyTest1 ();
New MyTest1 ();
New MyTest1 (). test ();
System. out. println ();
New MyTest1 (). test2 ();
System. out. println ();
}
}
Code 5:
Public class Parent {
Public Parent (String name ){
System. out. println (name );
}
}
Public class Children extends Parent {
Public Children (String name ){
System. out. println (name );
}

Public static void main (String [] args ){
New Children ("hello ");
}
}
Author: HarderXin

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.