Java foundation comprehensive title 2

First, the choice

  1. In a Java class, using the following () statement to define the public declaration of int constants MAX. (Radio)
    A. public int MAX = 100;
    B. Final int MAX = 100;
    C. public static int MAX = 100;
    D. Final public static int MAX = 100;
    Answer: D

  2. In Java, the following statement in regard to method overloadingerrorIs (). (Choose)
    A. The method of claim overloaded method must be the same
    list of parameters to be inconsistent overloads B.
    C. overloaded method's return type must match
    D. only a method in the class belongs is overloaded once
    The answer: CD

  3. The following code fragment will create several objects ().

String s1="bc";
String s2="bc";   

A. 2
B. 3
C. 0
D. 1

Answer: D

Parsing:
String str1 = "abc";
String str2 = "abc";
System.out.println (str1 == str2); // to true
1, note that we are not here with str1.equals (str2); way because this value comparing the two strings are equal. == Number, according to the instructions of the JDK, and only returns a true value only if two references point to the same object. And we are here to look at is whether str1 and str2 point to the same object.
2, the results show, JVM create two references str1 and str2, but only to create an object, and two references point to this object.

Str1 = String "abc";
String str2 = new new String ( "abc");
System.out.println (str1 == str2); // false
1, creates two references. It creates two objects. Two references point to two different objects.
2, the above described two pieces of code, as long as a new () to create a new object in the heap are created, and its value string is stored separately, even if the same data in the stack, and the stack is not data sharing.

Value data types of packaging can not be modified. Not just the value of the String class can not be modified, all data types and packaging can not change its value inside. (StringBuffer can be changed), such as:
String s1 = "bc";
String s2 = s1;
s1 = "de";
then find the output s2 s2 still equals "bc"
This property is the String, and take up too much memory space , then only the StringBuffer / StringBuilder two classes.

4) In Java, the following description of the constructor is correct (). (Radio)
A. Class constructor must be explicitly defined
B. constructor return type is void
C. constructors have the same name and type, and can not take any argument
D. class defines a plurality of constructors
Answer: D

5) What about garbage collection narrative is right.
A. garbage collector can free the memory used by the java object at a desired time.
B. garbage collection will check and release unused memory.
C. garbage collector allows program developers to explicitly and immediately release the memory.
D. program developers themselves have to create a thread to release the memory work.
Answer: B

6) the following statement regarding the options package in JavaerrorIs (). (Radio)
A. property privatization package is to provide a method of public access to a private property
B. The method includes accessing property setter and getter methods Method
C. setter methods for the assignment, the values for getter method
D. Class property must be packaged, or can not be compiled
Answer: D

7) implemented in Java packages, the first step is to modify the visibility of the property to restrict access to the property, and the second step is to create value assignment method for access to the properties, the third step should be (). (Radio)
A. assignment and use methods to access property values
B. write common way to access the properties
C. and value in the assignment method, add access restrictions on property
D. write the main method to create an object, call the assignment and take method to access the value of property
Answer: C

8) Analysis of Java code as shown below, in which this keyword mean (). (Radio)

public class Test {
    private String name;
    public String getName() {
    return name;
  }
public void setName(String name) {
    this.name = name;  
  }
}

A.name attribute
internal references refer to like B.Test own behalf
C. Test class objects of other objects referenced Test
Method D. means located
Answer: B

9) In the Java language, the following description of the class inheritance, the right is (). (Radio)
A. A class can inherit more than one parent class
B. A class can have a plurality of child
C. all subclasses of the parent class // private methods not
D. subclass must be more than parent member methods
Answer: B

10) The following code is executed, the following description is correct ()

public class Person{
   static int arr[] = new int[10];
   public static void main(String a[]){
     System.out.println(arr[1]);
   }
}    

A. gives compiler error
B. empty output
C. built correctly, run the wrong
D. Output 0
Answer: D

11) the following options to say about the super keyword in JavaerrorIs (). (Radio)
A. Super keyword is within the subclass object to refer to the parent class object reference
B.super keyword can refer not only to the direct parent on behalf of the subclass, can also refer to the parent on behalf of the parent class
C. subclass can call the parent class's method with the super keyword
D. subclass can attribute the super keyword to call the superclass
Answer: B

12) The following creates several objects

String A,B,C
A="a";
B="b":
A=A+B;
StringBuffer D=new StringBuffer("abc");
D=D.append("567");

A. 6
B. 4
C. 3
D. 5
Answer: B

13) the following statement on the Object classerrorIs (). (Radio)
A. All class directly or indirectly inherits from the Object class
B. Interface Object class also inherits
C. Object class defines toString () method
D. Object class in the java.lang package
Answer: B

14) given below Java code, after running the compiler, the output is (). (Radio)

class Parent {
  public void count() {
    System.out.println(10%3);
  }
}
public class Child  extends Parent{
  public void count() {
    System.out.println(10/3);
  }
  public static void main(String args[]) {
    Parent p = new Child();
    p.count();
  }
}

A. 1
B. 1.0
C.3
D. 3.3333333333333335
Answer: C

15) follows Java code, if you want to output "test class B () method" on the console, the horizontal line should be filled in at (). (Multiple choice)

class A {
    public void test() {
        System.out.println("A类的test()方法");
    }
}
class B extends A {
    public void test() {
        System.out.println("B类的test()方法");
    }
    public static void main(String args[]) {
            ________________                               
    }
}

A.A a = new B();
a.test();
B. A a = new A();
a.test();
C. B b = new A();
b.test();
D.B b = new B();
b.test();

The answer: AD

16) the following statements about Java interfaceerrorIs (). (Radio)
A. a Java interface is a collection of some of the features of the method, but there is no implementation of the method
B. Java method defined in the interface is implemented in a different place, you can have completely different behavior
C.Java interface can be declared private members of the
D. Java interfaces can not be instantiated

Answer: C
all member variables in the interface defaults to public static final, the interface is public, there can not have a private method or variable is used to let other people use.
All interface methods are public abstract public abstract, and can not have constructor.

17) given by Java code, a solution of () statement at the horizontal line, can compile the code. (Multiple choice)

interface Parent{
    public int count(int i);
}
public class Test implements Parent {
    public int count(int i){
        return i % 9;
}
  public static void main(String[] args){
        ________________
        int i = p.count(20);
    }
}

A.Test p = new Test();
B.Parent p = new Test();AB
C.Parent p = new Parent();
D. Test p = new Parent();
The answer: AB

18, set String s = "story"; the following options written statement is correct ().
= S + A. "Books";
B. C char = S [. 1];
C. int len = S .length;
D. S = S - "Books";

The answer: A
length () is seeking the number of String objects in a string of characters, and length is seeking an array of strings in the number of strings.

19, three kinds of empty string string determination method:
. 1: BOOL isEmpty = (str.length == 0);
2: BOOL isEmpty = (== String.Empty STR);
. 3: BOOL isEmpty = (STR == "" );
which method is correct? (). (Select one)
A. B. 2. 1. 3 C.
Answer: C

20, the following statement is correct (). (Multiple choice)
A. the Java language allows only single inheritance
B. Java language allows only one interface
C. Java language does not allow inherit a class implements an interface and
single inheritance D. Java language makes the code more reliable.
The answer: AD

21, the results of the program are the following (). (Radio)

class A{
  static{
     System.out.print("a");
  }
  public A (){
     System.out.print("x");
   }
}

class B extends A{
   static{
      System.out.print("b");
   }
   public B (){
      System.out.print("y");
   }
}

public class Test{
public static void main(String[] args){
     A ab = new B ();
     ab = new B ();
  }
}

A、abxyxy
B、axxybx
C、abyxyx
D、xyxyab
Answer: A

22, in the definition of the class with the same name can have two functions, a phenomenon known function ().
(A) package (B) inherits
(C) cover (D) Overloaded
Answer: D

23, in the definition of the role of class constructor is ().
Member variable (A) protective member variable (B) of the read class
characteristic (C) described Class (D) initialize member variables
Answer: D

24. Which of the following is not legal Java identifier ().
(A) $ persons (B) twoNum
(C) _myVar (D) * Point
The answer: D
1, the first letter of the English alphabet, $ and underscores, letters, numbers, and underscores.
2, the variable name with multiple words hump naming nomenclature composition. [For example: setAge]
3, variable names do not use Java keywords

25, the following is illegal (). (Multiple choice)
(A) the I = int 32; (B) a float F = 45.0;
© Double D = 45.0; (D) C char = 'U'; 
The answer: BD

26, described below with respect to the default constructor is correct ()
A. When a class is not the definition of any constructors, Java compiler will create a default constructor of this class
B. The default constructor can initialize other methods variables defined in
C. Java compiler will create all of the default constructor for the class.
D. If the constructor method defined in a class are declared parameters, Java compiler will create a default constructor of this class
Answer: A

27, following which the class definition is the definition of legitimate abstract class? ()
A, abstract Animal {abstract void Growl ();}
B, class abstract Animal {abstract void Growl ();}
C, abstract class Animal {abstract void Growl ();}
D, abstract class Animal {abstract void Growl ( ) {System.out.println ( "growl") ;};}
Answer: C

28, the relationship between the cover is overloaded ()
A, covering only occurs between the parent class and subclass of overload may occur in the same class
B. Covering methods may be different name, but overloaded methods have the same name as
C. The final modification methods can be overridden, but can not be overloaded
D. Cover and reload the same thing
Answer: A

29, access is not allowed as a class and the class members control character is ().
Private public B. A.
C. D. protected static
Answer: C

30, on selecting which of the following statements is correct structure? ()
A. if statements and else statements must appear in pairs
B. if there is no else statement statement can correspond
C. switch structure in each case statement must break statement
D. switch structure must have a default statement
Answer: B

Published 35 original articles · won praise 24 · views 60000 +

Guess you like

Origin blog.csdn.net/thumbs_up_sign_ygj/article/details/104985540