import java.util.*;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.time.*;
import java.time.format.*;
class A{
int A=100;
public void test(){
System.out.println("testA");
}
public void test2(){
System.out.println("test2");
}
}
class B extends A{
int A=1000;
public void test(){
System.out.println("testB");
}
public void test3(){
System.out.println("test3");
}
}
class c extends A{
int A=1000;
public void test(){
System.out.println("testc");
}
public void test4(){
System.out.println("testc");
}
}
//If you prepare a constructor in the superclass, it will always be called by the super in the derived class, but if there is no argument, it will be called explicitly.
//It is not necessary, and it is OK to call the constructor of the superclass when moving to another constructor with this etc.
class spclass {
int A=1000;
spclass(String s){
System.out.println("Superclass constructor");
}
}
class konsutoTest extends spclass{
int A=1000;
konsutoTest(){
this("s");
System.out.println("Derived class constructor");
}
konsutoTest(String s){
super("s");
System.out.println("Derived class constructor");
}
}
interface intaTest{
public void process(); //Public if nothing is attached to the modifier
}
class Sample implements intaTest{
public void process(){}; //You have to be public or strong
}
public class Main {
protected static int st;
protected static boolean bl;
protected static int[] bll;
protected static String stt;
protected static ArrayList ALL;
protected static ArrayList ALL2;
protected static StringBuilder stb=new StringBuilder(5);
public static void main(String[] args) throws Exception {
//Review of default constructor
new konsutoTest();
//Polyforism
//Put an instance of B in A, but in the end the instance of B is just a diff of A
//If you put it in the box of A, you can only see the thing of A, but the overridden method is reflected in A
//Since the value of the field is output according to the box, be careful if it is overridden if there is a problem with politics.
A a=new B();
a.test();
a.test2();
System.out.println(a.A);
B b=(B)a;
b.test3();
System.out.println(b.A);
// Your code here!
//Date problem
//LocalDateTime date = LocalDateTime.of(2015,9,15,1,1);
LocalDate date = LocalDate.of(2015,9,15);
System.out.println(date);
System.out.println(date.format(DateTimeFormatter.ISO_DATE));
double ddd=10.1d;
float fff=10f;
int iii=100;
String sss;
long lll=10;
ddd=fff;//Small to big is OK
fff=(float)ddd;//Cast from big to small
ddd=iii;
iii=(int)ddd;//When cast, it loses digits
double v=10.0+10;//because int is in double
long l=10+10;//Because the int type implicitly changes to LONG
lll=lll+iii;//It's okay because long also contains int
System.out.println("StringBuilder<StringBuilder> =initial value" + stb.toString() +"StringBuilder<StringBuilder> =number" +stb.length());//NULL because it is a reference type
try{
RuntimeExceptionTest();
}
catch(RuntimeException e){
System.out.println(e);
}
try{
bll=new int[3];
ArrayList<Integer> ll = new ArrayList<Integer>();
ArrayList<String> list = new ArrayList<>();//No because there is a type designation
ArrayList list2 = new ArrayList();//Anything is OK because it is generic and no type is specified
System.out.println("ArrayList<Integer> =" + ALL2);//NULL because it is a reference type
System.out.println(list);//Since it is a reference type, NULLt However, when an instance is created, [] is entered.
ll.add(10);
list.add("10");
list2.add('B');
System.out.println(ALL2);//NULL because it is a reference type
System.out.println("ArrayList<Integer> =" + ll);//NULL because it is a reference type
System.out.println("ArrayList<String>=" + list);//Since it is a reference type, NULLt However, when an instance is created, [] is entered.
System.out.println("string=" + stt);//NULL because it is a reference type
System.out.println("array=" + ALL);//Since it is a reference type, NULLt However, when an instance is created, [] is entered.
System.out.println(bl);
System.out.println(bll[0]);
System.out.println(bll.length + "← Number of arrays Contents" + bll[0]);//You can get the number with just the instance of the array. The contents are initialized with 0.
System.out.println(args);//args must be int[0]Make a hash code with 0 numbers
//Exceptional practice
Main.test();
System.out.println("XXXXXXXX");
}
catch(RuntimeException e){
System.out.println(e);
}
catch(Exception e){
System.out.println("Not reachable");
}
}
public static void RuntimeExceptionTest()
{
//Unchecked exception: You don't have to throw it, catch it at the caller
//It is not necessary to describe it.
if(2==1)
{
throw new RuntimeException();
}
else{
throw new NullPointerException();
}
}
public static void test() throws Exception
{
//throws throws an error to the caller for processing by the caller
st=100;
if(1==1)
{
throw new RuntimeException();
}
else
{
throw new Exception();
}
}
}
Recommended Posts