Daily Java practice questions (a little progress every day series)

prompt: A lot of friends reported that it’s not good to see the answer directly, then I willThe color of the answer is set to transparent, The answer is still behind the question, you need to select it with the mouse to see it (as shown in the figure below). At the same time, I will put all the answers at the bottom of the article for my friends on the mobile phone (the mobile phone can also be selected by long pressing). Friends who make a little progress every day have a better experience.I'm late, but I'm not absent. I will try to ensure that I have more Java practice questions every day. At the end of the article, there is the [Java Engineer Knowledge Graph] limited-time benefit discount, which is exclusively produced by CSDN for everyone, to help you grow! Come on! Make a little progress every day!

Insert picture description here

1The main method is the entry point for the execution of the Java Application program. The following describes which item is legal ().
Correct answer: B Your answer: B (correct)
public static void main()
public static void main( String args[])
public static int main(String [] arg)
public void main(String arg[])

Solution:
The name of the method must be main, the method must be of public static void type, and the method must receive an array of strings. The parameters string[] args and string args[] are the same

2In general, which of the following options is not the matching relationship between the relational data model and the object model?
Correct answer: D Your answer: D (correct)
Table corresponding class
Record corresponding object
Table field corresponds to class attribute
The reference relationship between tables corresponds to the dependency relationship between classes

Problem solution:
There is the following correspondence between the general relational data model and the object data model: the table corresponds to the class, the record corresponds to the object, and the fields of the table correspond to the attributes of the class. The relationship between the class and the class is mainly reflected in the operation of the relationship between the table and the table. They are all operations on the object. In our program, all tables and classes are mapped together. They pass the many- in the configuration file. to-one, one-to-many, many-to-many

3、The following statement about the mixed use of modifiers is wrong ()
Correct answer: D Your answer: D (correct)
Abstract cannot be modified in parallel with final in the same
class. There should be no private members
in the abstract class. The abstract method must be in the abstract class. Or the
static method in the interface can directly call the non-static properties in the class

Solution:
1. Abstract cannot be used to modify the same pair in parallel with final.
2. There should be no private members in the abstract class. Right: There can be private in the abstract class, but it shouldn't.
3. The abstract method must be correct in the abstract class or interface: If the method in the class is modified with abstract, the class must be modified with abstract. The interface methods are public abstract by default.
4. The static method can handle non-static attribute errors: in the JVM, the static method is in the static area, and the static area cannot call the non-static area attributes.

4, A certain program requires that each input can only be a positive integer, and the value of each input must be a multiple of 100 and less than or equal to 500, then which of the following is the correct invalid equivalence class ()
Correct answer: D Your answer: D (Correct)
(0, 100), (100, 200), (200, 300), (300, 400), (400, 500), (500, +∞);
(500, +∞)
(500, + ∞), any integer greater than 0 and less than 500 that is not a multiple of 100;
(-∞, 100), (100, 200), (200, 300), (300, 400), (400, 500), (500, + ∞);

Solution: The
invalid equivalence class is the opposite of the effective equivalence class, that is, a collection of invalid input data that does not meet the program input requirements.

5, According to the following code segment, the correct statement in the following is ().
public class Parent { private void m1(){} void m2(){} protected void m3(){} public static void m4(){} } Correct answer: C Your answer: C (correct) subclasses must be able to Inherit and override the m1 method of the Parent class. The subclass must be able to inherit and override the m2 method of the Parent class. The subclass must be able to inherit and override the m3 method of the Parent class. The subclass must be able to inherit and override the m4 method of the Parent class.









Solution:
Through inheritance, subclasses can have all methods and domains visible to the parent class
. A. Private methods can only be visible in this class, so they cannot be inherited. A error
B. The default access modifier is only visible in this package. , Invisible in outsourcing, B error
C. The protection modifier can be accessed by all subclasses inherited from this class, and of course it can be overwritten by inheritance; C correct
D.static modified members belong to class members, and the parent class field or method only Can be obscured by subclass field or method with the same name, cannot be overwritten by inheritance, D error

6, When creating a derived class object, the execution order of the constructor function ()
Correct answer: A Your answer: A (correct)
Base class constructor, derived class object member constructor, derived class constructor function
derived class constructor function , Base class constructor, object member constructor
base class constructor, derived class’s own constructor, derived class object member constructor
object member constructor, base class constructor, derived class’s own constructor

Solution:
The initialization process of the class is the process of method execution.
The static domain of the parent class-the static domain of the child class The non-static domain of the parent class-the constructor of the parent class The non-static domain of the child class-the law of the constructor of the child class is that the parent class precedes the subclass static before the non-static
The static domain contains static code blocks and static methods. Whoever is in front will be executed first.
The same for non-static domains

7, Regarding the following piece of code, which of the following statements are correct:

public static void main(String[] args) {
    String a = new String("myString");
    String b = "myString";
    String c = "my" + "String";
    String d = c;
    System.out.print(a == b);
    System.out.print(a == c);
    System.out.print(b == c);
    System.out.print(b == d);
}

Correct answer: AD Your answer: AD (correct)
System.out.print(a == b) prints false
System.out.print(a == c) prints true
System.out.print( b == c) What is printed out is false
System.out.print(b == d) What is printed out is true

Solution:
A: a points to the heap memory, b points to the constant pool, so the addresses are not equal, false
B: java has a constant optimization mechanism, c also points to the constant pool, and b points to the same, then the addresses of a and c are not equal, false ;
C: b and c address are equal, true
D: d is a copy of c, the address is the same, so b and d address are equal, true

8, For the following code, which options are true after execution: ()

class CompareReference{
   public static void main(String [] args){
   float f=42.0f;
   float f1[]=new float[2];
   float f2[]=new float[2];
   float[] f3=f1;
   long x=42;
   f1[0]=42.0f;
  }
}

Correct answer: BC Your answer: BC (correct)
f1==f2
x==f1[0]
f1==f3
f2==f1[1]

Solution:
B option: x == f1[0], x is a long type, which is of low precision compared with float type, so x has to be converted to a high-precision float type and then compared, so it is equal;
C option: f1 == f3, F3 is not created by new, but assigned by f1, so the f3 address points to f1, and the value of f1 changes, which is equivalent to changing the value of f3, so they are equal.

9, Which of the following JVM garbage collection methods use the replication algorithm to recover the
correct answer: AD Your answer: AD (correct)
New generation serial collector
Old generation serial collector
Parallel collector
New generation parallel collection collector
Old generation parallel Recycling collector
cms collector

Problem solution:
Two basic java recycling algorithms: replication algorithm and mark cleaning algorithm.
Replication algorithm: two areas A and B. The initial object is in A, and the surviving objects are transferred to B. This is the most commonly used algorithm in the new generation.
Mark cleaning: mark an area, mark reachable objects (reachability analysis), and then reclaim unreachable objects, and fragments will appear, then the
mark-defragmentation algorithm: more defragmentation, sort out more Larger objects store larger objects.
Two concepts: the new generation and the old generation. The
new generation: the initial object, with a short life cycle. The
permanent generation: the long-lived object. The
entire java garbage collection is a collaboration between the new and the old generation This is called generational collection.
PS: The Serial New collector is a collector for the new generation, using the replication algorithm
Parallel New (parallel) collector, the new generation uses the replication algorithm, and the old generation uses the mark to organize the
Parallel Scavenge (parallel) collector. For the new generation, Adopt the
serial old (serial) collector of the copy collection algorithm , the new generation adopts the copy, the old generation adopts the mark sorting
Parallel Old (parallel) collector, for the old generation, the mark sorting
CMS collector, based on the mark cleaning
G1 collector: overall It is based on mark sorting, partial copying. In
summary: the new generation basically uses the copy algorithm, and the old generation uses the mark sorting algorithm. cms uses mark cleaning.

10, What modifiers can be used to modify the local inner class?
Correct answer: CD Your answer: CD (correct)
public
private
abstract
final

Solution:
Local internal classes are placed in code blocks or methods, and cannot have access control modifiers, and cannot be modified with static

Answer summary:
1. Correct answer: B
2. Correct answer: D
3. Correct answer: D
4. Correct answer: D
5. Correct answer: C
6. Correct answer: A
7. Correct answer: AD
8. Correct answer: BC
9. Correct answer: AD
10. Correct answer: CD

Some of the above questions are from the Niuke comment area, thank you for the explanation of the comment area.

CSDN official exclusive production of [Java Engineer Knowledge Graph] limited-time benefits, details use WeChat scan code to view, it is good for someone to lead the way on the way to growth, learn the system, come on, make a little progress every day!

Insert picture description here
Make small but daily progress!
If you don't advance, you will retreat!

After reading, if it is helpful to you, thank you for your support!
If you are on a computer side, you will see "One key triple connection"Are you done, right click on it [haha]

Insert picture description here


Come on!

Work together!

Keafmd