2015.10.13 Classroom

Source: Internet
Author: User

Classroom examples

Classandobjecttest.java

Results

Hellow.java source program and results

There's nothing special about the output.

Initializeblockdemo.java source program and results

Mypackageclass.java source program and results

Objectequals.java source program and results

Strangeintegerbehavior.java source program and results

Test1.java source program and results

String Reverse output

Test2.java source program and results

Reverse output of the calling function

Test3.java source program and results

In the same package, the reverse output is called.


Class Root
{
static{
SYSTEM.OUT.PRINTLN ("Static initialization block of Root");
}
{
System.out.println ("Root's normal initialization block");
}
Public Root ()
{
SYSTEM.OUT.PRINTLN ("Root parameter-free constructor");
}
}
Class Mid extends Root
{
static{
SYSTEM.OUT.PRINTLN ("Static initialization block of mid");
}
{
SYSTEM.OUT.PRINTLN ("Normal initialization block for mid");
}
Public Mid ()
{
SYSTEM.OUT.PRINTLN ("Non-parametric constructor for mid");
}
Public Mid (String msg)
{
Calling overloaded constructors in the same class through this
This ();
System.out.println ("Mid with parametric constructor, its parameter value:" + msg);
}
}
Class Leaf extends Mid
{
static{
SYSTEM.OUT.PRINTLN ("Static initialization block of the Leaf");
}
{
SYSTEM.OUT.PRINTLN ("ordinary initialization block of the Leaf");
}
Public Leaf ()
{
A constructor that invokes a string argument in the parent class through Super
Super ("Java Initialization sequence demo");
System.out.println ("The constructor that executes the leaf");
}

}

public class Teststaticinitializeblock
{
public static void Main (string[] args)
{
New Leaf ();

}
}

Results

Static initialization block of root
Static initialization block for mid
Static initialization block of the leaf
Common initialization block for root
The parameterless constructor of root
Normal initialization block for mid
Parameter-free constructors for mid
The parametric constructor for mid, with parameter values: Java Initialization sequence Demo
Ordinary initialization blocks of the leaf
The constructor that executes the leaf

2015.10.13 Classroom

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.