JAVA test (multiple choice)

1. Analyze the Java code shown below, where the this keyword means ( )

Public class Test {

Private String name;

Public  String getName(){

   Return name;

}
public void setName(String name){

    This.name = name
}
}

Answer: The internal reference of the Test class refers to a reference to itself


2. Use Java to implement encapsulation. The first step is to modify the attribute visibility to access the attribute. The second step is to create assignment and value methods for accessing the attribute. The third step should be

Answer: Write the main method to create objects, call assignment and access methods to access properties


3. Given the Java code as shown below, the overloaded method for cal is

public class Test{

     public void cal(int x,int y,int z){  }

}

Answer: public void cal(int x,int z){}


4. Which of the following options is wrong about encapsulation in Java?

 A encapsulation is to privatize and provide common methods to access private properties
 B property access methods include setter methods and getter methods
 C setter method is used for assignment, getter method is used for value
 The properties of class D must be sealed, otherwise they cannot be compiled
5. In the Java language, the following description about inheritance of classes
 A A class can inherit from multiple parent classes
 B A class can have multiple subclasses
 C subclasses can use all methods of the superclass
 D subclass must have more member methods than superclass
6. In Java, which of the following statements about constructors is correct
 Class A must explicitly define a constructor
 The return type of the B constructor is void
 C constructors and classes have the same name and cannot take any parameters
 D A class can define multiple constructors
Correct answer: D
7. Which of the following statements about the Object class is wrong is
 A All classes are directly or indirectly inherited from the Object class
 The B interface also inherits the Object class
toString is defined in the C Object class
 D Object class is in java.lang package

8. In Java, which of the following statements about method overloading is false
 A method overloading requires that the method names must be the same
 B emphasizes that method parameter lists must be inconsistent
The return type of the C overloaded method must be the same
 D A method can only be overridden once in all its owning classes
9. The wrong statement in the super keyword in Java is
 A super keyword is a reference inside a subclass object that refers to its superclass object
The B ssuper keyword can refer not only to the direct parent class of the subclass, but also to the parent class of the parent class
 C subclasses can use the super keyword to call the methods of the superclass
 D subclasses can call the properties of the superclass through the super keyword

10. Which of the following statements about Java interfaces is false

 A A Java interface is a collection of method characteristics, but no method implementation
 Methods defined in B Java interfaces are implemented in different places and can have completely different behaviors
 Can declare private members in C Java interface
 D Java interface cannot be instantiated

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324621722&siteId=291194637