Java after class thinking questions

Source: Internet
Author: User

---restore content starts---

1. Is there really only one common class in a Java class file?

There can be only one public class in a Java class file

2. Do you have errors using Eclipse or Javac to detect the following code?

In Java, a class can be defined inside another class or inside a method, and such a class is called an inner class. The broad range of internal classes generally includes these four types: member inner class, local inner class, anonymous inner class, and static inner class. Intra-class detailed links: http://www.cnblogs.com/dolphin0520/p/3811445.html

3. Is the conclusion on public classes also available for interfaces?

The interface in Java is the declaration of a series of methods, is a collection of methods features, an interface only the method of the characteristics of the method is not implemented, so these methods can be implemented in different places by different classes, and these implementations can have different behavior (function), and Java class file, The name of the interface file must be the same as the interface name. A class can have multiple interfaces.

4. Why is the Java rule static as the main () method of the entry point of the program?

A non-static method requires an object to execute, and the static method can be executed only by the class. And the main method is the program just started to run the program, so there is no object, so Java rules The main method is static.

5.Java variables follow the "shielding principle of the same name variable", please read the relevant information after class to find out the relevant knowledge, and then write some test code, as in this example, consciously define some of the same name variables in different places, to see exactly what the output is.

public class Test {

int a=1;
public static void Main (string[] args) {
Test t=new test ();
b b=new B ();
int a=2;
System.out.println ("Main (). a=" +a);
T. print_a ();
B.print_b ();

}
public void Print_a () {
int a=4;
System.out.println ("Print_a (). a=" +a);
}

}
Class b{
void Print_b () {
int a=3;
System.out.println ("print_b.a=" +a);
}
}

5. Look at this diagram, and then look at the number of bits in Java for each data type, and the range of values that you can draw.

An int 32-bit value range is 2 of the 31-square-to-2-31-square-minus-1-any integer ( -2147483648~2147483647)

Short 16-bit value range is any integer between -32768~32767

A long 64-bit value range is 2 of 63 square to 2 of any integer ( -9223372036854774808~9223372036854774807) between 63 times minus 1

Float 32-bit value range 3.402823e+38 ~ 1.401298e-45

A double 64-bit value range is 1.797693e+308~ 4.9000000e-324

Char 8-bit value range is -128~127

A byte 8-bit value range is any integer between -128~127

Conclusion: The larger the number of data types in Java, the greater the range of values. Conversion from the low to the high number type may have a loss of precision.

6. Please run the following code (TESTDOUBLE.JAVA)

public class Testdouble {

public static void Main (String args[]) {
System.out.println ("0.05 + 0.01 =" + (0.05 + 0.01));
System.out.println ("1.0-0.42 =" + (1.0-0.42));
SYSTEM.OUT.PRINTLN ("4.015 * 100 =" + (4.015 * 100));
System.out.println ("123.3/100 =" + (123.3/100));
}
}

Experimental results:

0.05 + 0.01 = 0.060000000000000005

1.0-0.42 = 0.5800000000000001

4.015 * 100 = 401.49999999999994

123.3/100 = 1.2329999999999999

Why is the numeric value of a double type not "mathematically accurate" result?

The values we give, in most cases, require more digits than 64bit to be accurately represented (even in the case of infinite digits), and the double type is only 64bit, and the number of digits behind it will definitely lead to a false

"Mathematically accurate" results are not available.

7.

What is the output of the following code?

int x=100; int y=200;

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

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

Why is there such an output result?

Java after class thinking questions

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.