Java Basics Questions and Answers (own understanding)

Source: Internet
Author: User

1. Given the following Java program fragment: Class A{public A () {System.out.println ("a");} class B extends a{public B () {System.out.println ("B");} public static void Main (string[] args) {b b=new B ();}} The above procedure will (). (Select an item)

[Answer b]

A, cannot compile

b, by compiling, the output is: A b

C, through the compilation, output is: B

D, by compiling, the output is: A

2, a Java program has the following code: Datalnputstream din=new datainputstream (New Bufferedinputstream fileinputstream ("Employee.dat ”) )); Suppose that there are only a few characters in the Employee.dat file: ABCDEFG. Then: System.out.println (DIN) is printed on the screen (). (Select an item)

[Answer:]

A, a

B, b

C, 97

D, 98

3, given the Java code fragment, as follows: int i=0,j=-1; switch (i) {case 0,1:j=1; case 2:j=2;} System.out.print ("j=" +j); Compile-run, the correct is (). (Select an item)

[Answer: A, if written as an int i=0,j=-1; switch (i) {case 0:j=1; 1:j=1] System.out.print ("j=" +j); the output is j=2, and if you add a break after the case according to the normal wording, the output is j=1]

A, program compilation error

B, J=1

C, j=2

D, j=0

4. In Java, the following description of the constructor is correct (). (Select an item)

[Answer: D]

A, the class must have an explicit constructor (the system defaults to add a constructor to a class that does not have a constructor defined, and is hidden)

B, its return type is void (although the constructor does not return any value, but does not mean that it is a void type)

C, it and the class have the same name, but it cannot take any arguments (obviously, constructors can have parameters)

D, none of the above

5. In Java programming, when the components in a swing package handle events, the following () is correct. (Select an item)

[Answer:]

A, the components in the swing package is also the use of the event authorization model to handle the event

B, the type of event generated by the component in the swing package, also with a J-letter, such as: jmouseevent

C, the components in the swing package can also take the event delivery processing mechanism

D, swing package components corresponding to the event adapter also has a J-letter, such as: Jmouseadapter

6. Public class Eqtest {public static void main (String args[]) {eqtest e=new eqtest ();} Eqtest () {String s= "Java"; String s2= "Java"; Place the test code {System.out.println ("equal");} else {System.out.println ("unequal");} In the comment line position of the Java code above, placing () the test code can output an "equal" result. (Select an item)

[Answer: C, it is necessary to note that S and S2 are not the same case, so it is not judged by equals]

A, if (S==S2)

B, if (s.equals (S2))

C, if (s.equalsignorecase (S2))

D, if (S.nocasematch (S2))

7. In the descriptor of the class, data that is specified as private can be accessed by the following (). (Select an item)

[Answer: C, private data can only be used by member functions in the class in which it resides]

A, any function in the program

B, member functions of other classes

C, member functions in a class

D, member functions in derived classes

8. In Java programming, the following () command is used to execute Java class files. (Select an item)

[Answer: B,javac is used to compile. java files, Java is used to execute. class Files]

A, Javac

B, Java

C, Appletviewer

D, all of the above options are not correct

9. In Java, the following methods can correctly create a Swing tab component () (select two)

[Answer:]

A, ImageIcon icon = new ImageIcon (

B, ImageIcon icon = new ImageIcon (

C, ImageIcon icon=new ImageIcon (

D, JLabel label=new JLabel (swingconstants.left);

10. Analyze the following Trythis () method written in the Java language: public void Trythis () {try{System.out.print ("a"); problem ();} catch (RuntimeException e) {System.out.print ("B");} catch (Exception e) {System.out.print ("C");} finally{System.out.print ("D"); System.out.print ("E"); When the method is invoked, if the problem () method throws an exception of a runtimeexception class, the output will be (). (Select an item)

[Answer: c] I personally analysis that is C, but not 100% sure, if it is different from my answer, please explain the view.

A, ABCDE

B, Abd

C, Abde

D, Abe

11. Public class myclass1{public static void Main (String argv[]) {} _____ class Myinner {}} can be placed () modifiers on the horizontal line in the above Java code. (select three items)

[Answer: D]

A, public

B, Private

C, Static

D, Friend

  12, public class test3{public static void Main (String args[]) {for{int i=0;i<3;i++}{for{int j=3; j>0;j--} {If (i==j) continue; The

system.out.print}n ("i=" +i+ "j=" +j)}}}}

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.