Atomic operation (atomic operation) __ local variable-class variable

Source: Internet
Author: User
Tags c constructor

1 about static members and object members in C++/java the right thing to say is ()

A static member variable is generated when the object is constructed;
The B static member function cannot be invoked in the member function of the object;
C virtual member function cannot be a static member function
The D static member function cannot access the static member variable

Note: First of all: the so-called member functions and member variables are members of the class function;
A static member function is generated when the class is loaded, that is to say: It is generated before the constructor;
B static member functions can be accessed by a member function of a class, but static cannot access the member function of a class because it does not have the this pointer, which is irreversible;
Static can access static, static can not access non-static
Non-static access to static, non-static access to Non-static
C Virtual Members in Java is similar to the abstract method, that is, abstract methods can not be used static, final,native synchronized private to decorate.
Static is not a pointer, is a class level, so abstract methods (virtual methods) to use the class member functions to implement, at this point, if the static decoration is very unreasonable native is a method modifier. The native method is a local method implemented by another language (such as C/c++,fortran, assembler). Because the method is implemented externally, in Java code, there is no need to declare, somewhat like an interface method. Native can be used with some other cosmetic fonts, but the abstract method and interface method cannot be decorated with native.
Answer C

2 What is the result? ()
public class Test2 {

public static void Main (string[] args) {
    int x = 3;
    int y = 1;
    if (x=y)
    if (x==y)
        System.out.println ("not Equal");
    else
        System.out.println ("Equal");
}

}

A the output is "Equal"
B the output is ' not Equal '
C an error in line 5 causes compilation to fail;
D The program executes but does "not print a" message

Note: In Java the IF () parenthesis can only be true or false and in parentheses in the question is an assignment statement. Will complain, this is exactly the difference with if in C + +, if not "= =" in C + +, the result in parentheses will be the number greater than 0 to true, and will be less than 0 Converts the number to false
Answer: C
3 The following multithreading to the INT type variable x operation, which does not need to be synchronized ()

A  ++x
B  x=y
C  x + +
D  x=1  

Note: An atomic operation is examined: when a multiple process (thread) accesses a resource, it ensures that all other processes (threads) are not accessing the same resource at the same time. Atomic operations (atomic operation) do not require synchronized, which is a cliché of Java multithreaded programming. Atomic operations are not interrupted by thread scheduling mechanisms
Operation, which, once started, runs to the end and there is no context switch (switch to another thread), the atomic operation can be a step or multiple steps, but the order is not to be disturbed, or to cut off the only operative part.
Synchronization is a fear of being read by other threads while the operation is in progress, which is not the case when atomic operations occur. Because of the one-step operation, other threads cannot interfere in the middle. The other three items were read and operated in two steps, while X=1 was an atomic operation.
For example: X + + is first placed in the register from the read variable x, and then the number of registers stored in the operation + +, and then assigned to the memory of X.
Answer: D
4 The following description in the correct is ()
Class Person
{

String name = "No Name";
Public person (String nm)
{
    name = NM;
}

}
Class Employee extends Person
{

String emp = "xxxx";
Public Employee (String ID) 
{
    //super (ID);//no such
    emp = ID in the title;
}

}
public class Test4 {

public static void Main (string[] args {
    employee E = new Employee ("123");
    System.out.println (e.emp);
}

}
A output: xxxx
B output: 123
C compilation Error
D Output: No name

Note: In this question: The subclass executes the method of constructing the parent class before executing the construction method. If the constructor method that invokes the parent class is not displayed in the subclass, then the system gives the default constructor method to invoke the parent class, but: if the constructor method is defined in the parent class, then it is important to call the constructor method of the parent class through the child class arguments. If the call is not displayed, the system does not provide us with an parameterless constructor that invokes the parent class. The system will complain. Answer: C
5 The assertion of the Java constructor is correct ()

The return value of the A builder is void
B If there is more than one class in a source file, then the constructor must have the same name as the public class
The C constructor can have 0, 1, or more parameters
D Each class can have more than one constructor
Note: Answer: BC
Construction methods can overload
public class Test5 {

Class test{Public
    test ()
    {}
}
class test2{public
    test2 ()
    {}
} public
static void Main (string[] args) {
}

}

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.