1. A source program written in the Java language is saved with a file name extension of (B).
(A). Class (B). Java (C). CPP (D). txt
Note: The source file name extension for the Java language is. Java, which generates a. class file, which is the code file.
2. Set int a=-2, the value of the expression a>>>3 is (D).
(a) 0 (B) 3 (C) 8 (D) a large number
The result of the "note" test is 536870911. It involves the complement: the complement of a positive number is itself, and the complement of negative number is the negation +1.
3. With the definition of an array int[] a = new int[3], the following reference to the array element is wrong (C).
(A) a[0]; (B) a[a.length-1];
(C) a[3]; (D) int i=1; a[i];
4. There can be two functions of the same name in the definition of a class, a phenomenon called a function (D).
(A) Encapsulation (B) inheritance
(C) Overlay (D) overload
Note: You can have a method with the same name, but the parameter types and parameters cannot be the same, and this relationship embodies the polymorphism (overloading) in Java.
5. The function of a constructor in the definition of a class is (D).
(A) Protection of member variables (B) Reading member variables of a class
(C) Describe the characteristics of a class (D) Initialize member variables
The note constructor is typically used to automatically initialize an internal data member when instantiating an object, set an initial value, allocate memory space, and so on.
Destructors are used to remove objects, such as freeing up space for applications.
To create an object, you have to call the constructor.
To destroy an object, you are forced to call the destructor.
A static member function can also be called without creating an object if the member function declares static.
6. Which of the following keywords is not used for exception handling statements (B).
(A) Try (B) break
(C) catch (D) finally
7. The relationship of a class to an object is (a).
(A) A class is an abstraction of an object (B) An object is an abstraction of a class
(C) An object is a subclass of a class (D) class is a concrete instance of an object
The "note" object is an abstraction of an objective thing, and a class is an abstraction of an object. A class is an abstract data type, defined as: class name {}
Their relationship is that the object is an instance of the class, and the class is the template for the object.
8. Which of the following is an illegal identifier in Java (D)
(A) $persons (B) twonum
(C) _myvar (D) *point
"Note" Java The identifier must be ' $ ', ' _ ', or the letter ' a ' ~ ' Z ', ' a ' ~ ' Z ', and the next can be ' $ ', ' _ ', the letter ' a ' ~ ' Z ', ' a ' ~ ' Z ', the number ' 0 ' ~ ' 9 ' of any composition. There is no limit to the length of identifiers.
Identifiers cannot contain other symbols, and of course do not allow spaces to be inserted.
9. A method to write a method header for a non-formal parameter of class AB without a return value, so that it can be called using the class name AB as a prefix, the method header is in the form of (A).
(A) static void Method ()
(B) public void Method ()
(C) Final void method ()
(D) abstract void Method ()
Note
A is a static method that can call Test.method () directly in the following form;
B is the normal public function, the class must be instantiated, test test = new test (), Test.method ();
C is the final method, cannot be overloaded, uses the same B
D is an abstract method that must be inherited and rewritten by the quilt class and then invoked in the same way as B.
. To construct an instance of the ArrayList class that inherits the list interface, which of the following methods is correct (B).
(A) arraylistmylist=new Object ()
(B) listmylist=new ArrayList ()
(C) arraylistmylist=new List ()
(D) listmylist=new List ()
" Note "B is not C.
This is called interface-oriented programming, which is a great advantage of the Java language. ArrayList Although it is a specific class, according to ArrayList Mylist=new ArrayList (); indeed, a MyList object can be generated, and the compilation will not be an error. However, in the actual development is not used in this way that the actual development is the interface name Xxx=new interface of an implementation class (). This facilitates
1. easy to standardize the design of the program
2. Collaborative development with the team
3. easy to convert to components
4. Convenient code reuse, no need to know the technical details.
The 11.Java source file and the compiled file name extension are (B)
(A). Class and. java
(B). Java and. Class
(C). Class and. Class
(D). Java and. java
Note: The source file name extension for the Java language is. Java, which generates a. class file, which is the code file.
13. For a Java source file, the import, class definition, and package are in the correct order: (a)
(A) Package,import,class
(B) Class,import,package
(C) Import,package,class
(D) Package,class,import
14. Which of the following is illegal: (B)
(A) IntI = 32; (B) Float f = 45.0;
(C) Double d = 45.0;
(D) Char c = ' u '; Symbolic error
"Note" should be float f = 45.0f;
15. The character set used by the Java language is (D)
(A) ASCII (B) BCD
(C) DCB (D) Unicode
Note the character set used by the Java language is a 16-bit Unicode encoding.
16. If a member variable of a class can only be used in the same class, the modifier that the member variable must use is (C)
(A) public (B) protected
(C) Private (D) static
Note
Private The same class can be accessed;
Public can be accessed globally, subclasses, the same package, and the same class can be accessed);
protected is the same class, the same package, the subclass can be accessed;
The non-decorated symbol is the default type--default, which can be accessed within the same class, in the same package.
Static The modifier state to the first three is the modifier permission.
17. The following information about the main method is correct (B)
(A) Public main (String args[])
(B) public static void Main (String args[])
(C) private static void Main (String args[])
(D) void Main ()
"Note" as follows
18. Which keyword can be used to add mutexes to an object? B
(A) Transient (B) synchronized
(C) serialize (D) static
"Note"Synchronized thread Safety and synchronization.
19. The right thing to say about abstract methods is (c)
(a) can have method body (B) can appear in non-abstract class
(C) A method that does not have a method body
(D) methods in an abstract class are abstract methods
The "note" abstract method refers to methods that have only method declarations and no concrete method bodies. Abstract methods generally exist in abstract classes or interfaces. So the correct is C (no method body method).
The file class of the 20.java.io package is (b) Select D
(A) Character Stream class (B) byte stream class
(C) Object flow class (no this stream) (D) non-flow class
21. The main class in Java application needs to include the main method, which of the following is the correct parameter for the main method? b
A, String args B, string args[]
C, Char Arg D, stringbufferargs[]
22. The following code snippet executes after the output is (a)
int x=-3; int y=-10;
System.out.println (y%x);
A, -1 B, 2 C, 1 D, 3
"Note" Take the mold symbol and dividend consistent! The remainder, that is, the remaining value after the division, where 9 is rounded apart, and the remaining-1.
23. The following description of the inheritance is correct (a).
A. Classes in Java allow only single inheritance
B, in Java, a class can implement only one interface (multiple)
C, in Java a class cannot inherit a class at the same time and implement an interface (yes)
D, the interface in Java allows only single inheritance (Multiple inheritance possible)
24. If there is a definition: byte[] x={11,22,33,-66};
Where 0≤k≤3, the reference to the x array element error is (C)
A) x[5-3]
B) X[k]
C) x[k+5]
D) X[0]
26. Which of the following is not the original data type of Java (B)
A, int B, Boolean C, float D, Char
Note: The description of the uppercase letter is a Boolean wrapper class that inherits from Object. Just as an integer corresponds to an int, the same package, the subclass can be accessed.
27. In Java, a class can define many methods of the same name at the same time, the number, type, or order of the formal parameters of these methods are different, and the values returned can be different. This object-oriented program feature is called (C)
A) Hide
B) rewrite
C) overloading
D) Java does not support this feature
28. The following is a statement of the construction method, which is correct: (A)
A The construction method of a class can have multiple
B Constructed method is called when the class is defined
C The constructor method can only be called by other methods in the object.
D The construction method can have the same name as the class, or it can be different from the class name
The "note" construction method is called when the instance object is generated; The construction method cannot be called by other methods of the object; The construction method must have the same name as the class.
. Give the following code, which one of the following statements is true about the program? (b wrong) should choose c. A static method can only invoke a static member. Math.Abs ()
public class person{
static int arr[] = new INT[5];
public static void Main (String a[])
{
System.out.println (Arr[0]); }
}
A. Errors will be generated at compile time
B, compile-time correct, run-time will produce an error
C, Output 0
D, Output null
for a definition of the following methods, select the return type of the method (C-fault). Should choose D
ReturnType method (Byte x, double y)
{
Return (short) x/y*2;
}
A, Byte B, short C, int D, double
. What are the definitions of legitimate abstract classes in the following class definitions? C
a.abstractanimal{abstract void Growl ();}
B.classabstract animal{abstract void Growl ();}
C.abstract class animal{abstract void Growl ();}
D.abstractclass animal{abstract void Growl () {System.out.println ("growl");};}
. There are the following program fragments, which of the following options cannot be inserted into line 1. D
1.
2.public class interesting{
3.//dosth the inner class here, you can't write public.
4.}
A, import java.awt.*;
B, package mypackage;
C, Class otherclass{}
D, Publicclass myclass{} A class cannot have two public
Note: You cannot have two public classes, a is a reference package, B is a package creation, and C is a generic class.
34. The following two assignment statements are available:
A = Integer.parseint ("12");
b = integer.valueof ("n"). Intvalue ();
The following statement is correct (D).
A, A is an integer type variable, and b is an integer class object.
B, A is an integer class object and B is an integer type variable.
C, A, and B are integer class objects and have equal values.
D, A, and B are all integer type variables and have equal values.
"Note" Integer, which is a package of type int. There are some basic types in Java, such as a Boolean byte char short int long floatdouble
These types are bare types that are not encapsulated, and all the rest of the classes are inherited from the Objcet class. The bare type is detached from the inheritance tree of the class, but Java encapsulates all of these simple types, where the encapsulation of int is an integer
Parseinte and intvalue The return values of both methods are int.
a and B are integer-type variables, not integer objects.
37. In order for the package CH4 to be visible in the current program, the statement you can use is (A).
A) importch4.*; B) package ch4.*;
C) CH4 import; D) CH4 package;
please tell me, which class does all the exception classes inherit from? (B).
A) java.io.Exception
B) java.lang.Throwable
C) java.lang.Exception
D) Java.lang.Error
39. The package to use for basic Java GUI design is (C).
A) java.io B) java.sql
C) java.awt D) Java.rmi
40. When the mouse is clicked or dragged, which of the following events is triggered? D
A) keyevent B) ActionEvent
C) itemevent D) MouseEvent
Fill in the blanks questions:
1. Array x definition: String x[[]=new int[3][2]; X[0][0]= "abc", X[0][1]= "12345";
The value of X.length is __3__,x[0][1].length () of __5__.
2. The variables of the Java language are composed of variable name, _ modifier _, variable attribute, _ Initial value ___.
3, when you need to throw an exception in the program, you should use the _catch_ clause, when you need to declare a possible exception type in the method, you should use _ throws xxxexception _ clause.
6, Java source program files and bytecode file extensions are _.java__ and __.class__ respectively.
7. The Java language type checking mechanism requires that a method with no return value must be preceded by a __void____.
8. In the Java language, all objects are allocated memory through the _____new____ operator, and the memory is automatically managed.
10, each Javaapplication program can include many methods, but must have and only one __main_ method, the unified format is _public static void main (String[]args) {} _, which is the entrance of the program execution.
11, to define a common int class member variable max_length in the program, and the value of the variable holds the constant value 1000, the statement that defines the variable is public final int max_length=100___.
12. Subclasses must invoke the constructor of the parent class with arguments through the _ Super _ keyword.
13. In the Java language, all classes are subclasses of class __object __.
14, in the Java program, through the definition of the class can only achieve single-inheritance, but through the definition of the interface __ can achieve multiple inheritance relationships.
15. If you are in a Java program, you need to use Java. Util all classes in the package, you should add the statement _ Import java.util.* _ at the beginning of the program.
16, the following program operation result is ___01234_____
public class Ex2 {
public static void Main (string[] args)
{
for (int cnt=0;cnt<10;cnt++)
{
if (cnt==5)
Break
System.out.print (CNT);
}}}
17, the following program operation result is ______4_________
Import java.io.*;
public class atest{
public static void Main (String args[])
{
Subclass SB = new Subclass ();
System.out.println (Sb.fun ());
}}
Class superclass{
int a=24, b = 5;
}
Class Subclass extends Superclass
{
int fun ()
{
return a%b;
}
}
18, analysis The following procedures, fill in the blank place of the statement
Class Point//define coordinate classes
{int x, y;
Test (int a,int b)
{x=a;y=b;}
}
Class Rec extends point __________//definition Rectangle class
{
int length,width;
Rec (int a1,int b1,int l,int W)
{super (A1,B1);
Length=l;width=w;
}}
Class Test
{public static Voidmain (String args[])
{
___Test R1=new__rec (0,0,10,20) ___
Defines an object named R1 with the same initialization coordinates of 0, 0, length 10, and a width of 20
R1.print ();
}}
19, Java source files can only have _____1________________ public class, the number of other classes are unlimited.
20. All the multidimensional arrays implemented in Java are, in fact, arrays of arrays of one-dimensional arrays.
21, set x = 15, the value of the expression (x + +)/4 is ________3_____.
22. ___ The abstract ____ method is a method that has only methods head, no concrete method body and operation implementation, and the method must be defined in the abstract class.
23. The ___run () _______ method is used to define the execution body of the thread. The ______start () _____ method is used to start the thread.
24, String str1= "abc";
Stringstr2=new String ("abc");
System.out.println (STR1==STR2); After the program runs, the output is: ____fault__ (because the address is compared) _____
25. In the Java language, there is a class that is the parent class of all classes or interfaces, and the name of the class is ____object____.
26, when starting the applet program, the first method to call is _______init () ___. (Initialize component)
27, the Java language is a complete _____ object-oriented _____ programming language.
28. If a Java Applet source program file is defined with only one class and the class name is MyApplet, the class MyApplet must be a subclass of the ____applet_____ class and the file name of the file that stores the source program is the Applet 。
29. Set int x = 2, the value of the expression (x + +)/3 is _______0___________.
The access modifiers provided by 30.Java are: public, _private, protected, friend.
There are two commonly used string classes in Java, one is string and the other is _, StringBuffer _.
Note: A string is an object that will be generated each time it is used, whether you use = or new as the object.
StringBuffer just to make up the string, it can use append, which will not generate new objects after initialization, but she is thread insecure.
StringBuilder is thread-safe, so it's slower than StringBuffer, and the rest of them are the same.
There are two ways to implement multithreading in 32.Java, one method is to implement multi-threading by creating subclasses of the ___ thread ___ class, and the other is to define an implementation
____ Runnable __ The class of the interface.
33.Java does not support multiple inheritance. However, it allows a class to implement multiple ___ interfaces at the same time, which is equivalent to partially implementing multiple inheritance.
In a 34.Java source file, the ________import_____ statement is located after the package statement and before the class definition.
The _fileoutputstream__ class is a subclass of the OutputStream class that handles data streams that are output as data by the file.
Java Fundamentals Questions