Java Featured pen Questions

Source: Internet
Author: User
Tags access properties c constructor

EnCircle of wood, born in margins, nine-storey platform, from the base of the Earth; How about a quick test of your Java fundamentals?

1, the following statement is correct ()

A. Two public-modified classes can exist in a single file

B. Constructors can be overridden (override)

C. Subclasses cannot access properties of parent class non-public and protected adornments

D.final-Modified classes can be inherited

Answer: C

There can be at most one public class in a Java source file, and when there is a public class, the source file name must be the same, otherwise it cannot be compiled, and if there is no public class in the source file, the file name does not have a consistency requirement in the class. The main () does not have to be placed in the public class to run the program.

Overriding is when a subclass inherits a parent class and modifies the method of the parent class. The method name, parameter, and return value must be the same. You cannot override a method that is marked as final. If you cannot inherit a method, you cannot override this method.

Extension: overriding override, the difference between overloaded overload

method overloading for Java

Is that you can create multiple methods in a class that have the same name but have different parameters and different definitions. The method is invoked by the number of different arguments and parameter types passed to them to determine which method to use, and the return value type can be the same or not the same, which is also object-oriented polymorphism.

 Java method overrides

The polymorphism between the parent and child classes, redefining the functions of the parent class. If you define a method in a subclass that has the same name and arguments as its parent class, we say that the method is overridden (overriding). In Java, subclasses can inherit methods from the parent class without having to rewrite the same method. But sometimes subclasses do not want to inherit the parent class's methods, but want to make some changes, which requires a method of rewriting. Method overrides are also called method overrides.

If a method in a subclass has the same method name, return type, and parameter table as a method in the parent class, the new method overwrites the original method. If you need a method from the parent class, you can use the Super keyword, which references the parent class of the current class.

The access adornment permission of a subclass function cannot be less than the parent class;

Overriding methods can only exist in an inheritance relationship, overriding methods can only override the parent class's non-private methods.

2,for (int x=0,y=0; (y!=0) && (x<4); x + +) The number of executions of the loop is ()

A. Unlimited times

B. Execution 4 times

C. Implementation 3 times

D. No execution at a time

Answer: D

The y initial value is 0, in the entire for loop, the value of Y is not changed, so the judgment statement (Y!=0) is not established, it is not executed once.

3, about the JAVA heap, the following statement is wrong ()

A. Instances and arrays of all classes are allocated memory on the heap

B. The heap memory occupied by the object is reclaimed by the automatic memory management system

C. Heap memory consists of surviving and dying objects, free fragment area

D. Arrays are allocated in the stack

Answer: D

The first array is allocated in the heap, so the statement of D is incorrect.

Structure of the Java heap: The JVM heap is the run-time data area, and the instances and arrays of all classes are allocated memory on the heap. It is created when the JVM is started. The heap memory that the object occupies is reclaimed by the automatic memory management system, which is the garbage collector. Heap memory is made up of surviving and dying objects. The surviving objects are accessible to the app and are not garbage collected. The object of death is the object that the app is inaccessible and has not been reclaimed by the garbage collector. Until the garbage collector reclaims these objects, they will occupy the heap memory space.

4, when using the super and this keyword, the following description is correct ()
A. Use super () in the subclass construction method to display the constructor method of calling the parent class;

Super () must be written in the first row of the subclass construction method, otherwise the compilation does not pass
B.super () and this () do not have to be placed within the first line of the constructor method
C.this () and super () can appear in one constructor at a time
D.this () and super () can be used in a static environment, including static methods and static statement blocks

Answer: A

The Java keyword This can only be used in a method method body. When an object is created, the Java Virtual Machine (JVM) assigns a pointer to the object that refers to itself, which is the name of this pointer. Therefore, this can only be used in non-static methods in the class, and the static method and the static code block must never appear in this.

Super key is similar to this, is a masked member variable or member method or becomes visible, or is used to refer to a masked member variable and member member method.

However, super is used in subclasses in order to access the masked members in the immediate parent class, which is the immediate parent class (the closest superclass above the class)

5, which of the following statements is correct ()

A The Java program will generate machine code after compiling.

B The Java program generates a byte code after it is compiled

C A Java program compiles a DLL after it has been compiled

D None of the above is correct

Answer: B

Java bytecode is the intermediate file generated by the Java source file compilation

Java virtual machines are hypothetical computer Java that can run Java bytecode, and the cross-platform is also relative to other programming languages.

First introduce the C language of the compilation process: C file after the C compiler compiled after the generation of Windows executable EXE file and then execute in Windows.

Again, the Java compilation process: Java files are compiled by the Java program Java bytecode file is the class file in the Java Virtual machine execution. The machine code is executed by the CPU, and Java is compiled as a byte code.

The computer can only run machine code. Java turns bytecode into machine code when it is running. C + + compiles directly into machine code at compile time

6, which of the following statements is true ()

A The abstract modifier modifies fields, methods, and classes

B The body part of the abstract method must be wrapped in a pair of curly braces {}

C Declaring abstract methods, curly braces are optional

D Declaring abstract methods cannot write curly braces

Answer: D

The abstract modifier is used to decorate classes and Member methods

An abstract class is represented by a class that is abstracted, and the abstract class is located in the abstraction layer of the inheritance tree, and the abstract class cannot be instantiated.

Abstract methods are used to represent abstractions, and there is no method body for abstract methods. Abstract methods are used to describe what functions the system has, but do not provide specific implementations.

Abstract is an important keyword in Java that can be used to decorate a class or a method.

When a method is decorated, it means that the method has only signature signatures (signature), there is no specific implementation, but rather a specific implementation is left to inherit the subclass of the class, so there cannot be curly braces.

7, the following statements are correct ()

A The constructor in class must not be omitted

B Constructor must have the same name as class, but the method cannot have the same name as class

C constructor is executed when an object is new

D A class can only define one constructor

Answer: C

There may be misunderstandings here, in fact, the ordinary class method can be the same name as the class names, and the construction method is the only distinction is that the construction method does not return a value.

Whether the 8,GC thread is a daemon thread ()

Answer: Yes

Threads are divided into daemons and non-daemon threads (that is, user threads).

The daemon thread works as long as any non-daemon thread in the current JVM instance is not finished, and the daemon ends up working with the JVM only when the last non-daemon thread ends.

The most typical application for daemon threads is the GC (garbage collector)

9, about sleep () and wait (), one of the following descriptions of the error is ()

A. Sleep is a thread-class method, and wait is a method of the object class;

B. Sleep does not release object locks, wait to discard object locks;

C. Sleep pauses the thread, but the monitoring State remains, and the end is automatically restored;

D. Wait to enter the waiting lock pool, only after the Notify method is issued for this object to get the object lock into the running state.

Answer: D

Sleep is a threading class (thread) method that causes this thread to pause execution for a specified time, giving the execution opportunity to other threads, but the monitoring state remains and is automatically restored when it is finished. Calling sleep does not release the object lock.

Wait is a method of the object class that calls the wait method on this object to cause this thread to discard the object lock, enter the waiting lock pool waiting for this object, and only after the Notify method (or Notifyall) is issued for this object the thread enters the object lock pool ready to get the object lock into the running state.

10, Method Resume () is responsible for recovering which threads are executing ()

A, a thread that stops by calling the Stop () method.

B, the thread that is stopped by calling the sleep () method.

C, the thread that is stopped by calling the Wait () method.

D, the thread stopped by calling the Suspend () method.

Answer: D

Suspend can suspend a thread, which is to suspend the thread, it occupies the resource, but does not run, with resume is to resume the suspended thread, let this thread continue to execute.

Transfer from http://www.cnblogs.com/peke/p/7912888.html

Java Featured pen 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.