The second week of after-school learning hands-on brain operations && Homework second week of after-school learning hands-on brain operations && Homework

The second week of after-school learning hands-on brain operations && Homework

 

The first is to read and understand this code:

package first1;2904628156

public  class  EnumTest {

public static void main(String[] args) {

Size s=Size.SMALL;

Size t=Size.LARGE;

// s and t refer to the same object?

System.out.println(s==t);  //

// primitive data type?

System.out.println(s.getClass().isPrimitive());

// convert from a string

Size u=Size.valueOf("SMALL");

System.out.println(s==u);  //true

// list all its values

for(Size value:Size.values()){

System.out.println(value);

}}}

 enum Size{SMALL,MEDIUM,LARGE};

The first is for getClass (), isPrimitive () explanation:

Object class contains a method named getClass, this method can be obtained by using an instance of the class type. Type class refers to the representative of a type of class, because everything is an object, is no exception type, use type in Java class to represent a type. Examples of the types of all the classes are Class Class

isPrimitive (): boolean: determining whether the type is a primitive type, i.e., whether it is int, boolean, double and so on.

 

So the first s and t are not the same object, false output

Second place because getClass () base class is not output, so the false

Finally, the true value so that the same

Finally, traversing all the output values

 

The second test is the second segment of code

package first1;

import java.util.Scanner;

java.util.Random import;

public class second1 {

static Scanner sc=new Scanner(System.in);

public static void main(String args[]){

int x=100;

int y=200;

System.out.println("x+y="+x+y);

System.out.println(x+y+"=x+y");

The first is to read and understand this code:

package first1;2904628156

public  class  EnumTest {

public static void main(String[] args) {

Size s=Size.SMALL;

Size t=Size.LARGE;

// s and t refer to the same object?

System.out.println(s==t);  //

// primitive data type?

System.out.println(s.getClass().isPrimitive());

// convert from a string

Size u=Size.valueOf("SMALL");

System.out.println(s==u);  //true

// list all its values

for(Size value:Size.values()){

System.out.println(value);

}}}

 enum Size{SMALL,MEDIUM,LARGE};

The first is for getClass (), isPrimitive () explanation:

Object class contains a method named getClass, this method can be obtained by using an instance of the class type. Type class refers to the representative of a type of class, because everything is an object, is no exception type, use type in Java class to represent a type. Examples of the types of all the classes are Class Class

isPrimitive (): boolean: determining whether the type is a primitive type, i.e., whether it is int, boolean, double and so on.

 

So the first s and t are not the same object, false output

Second place because getClass () base class is not output, so the false

Finally, the true value so that the same

Finally, traversing all the output values

 

The second test is the second segment of code

package first1;

import java.util.Scanner;

java.util.Random import;

public class second1 {

static Scanner sc=new Scanner(System.in);

public static void main(String args[]){

int x=100;

int y=200;

System.out.println("x+y="+x+y);

System.out.println(x+y+"=x+y");

Guess you like

Origin www.cnblogs.com/fdfds228/p/11706145.html