[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