/**
*These 10 questions are all done by me. I have done them wrong or think they are valuable and need to be reviewed. I have compiled them to test everyone
*If you have better suggestions, please feel free to submit them.
*/
1. The code output result is
public class Test { public static void main(String [] args){ System.out.println(new B().getValue()); } static class A{ protected int value; public A(int v) { setValue(v); } public void setValue(int value){ this.value = value; } public int getValue(){ try{ value++; return value; } catch(Exception e){ System.out.println(e.toString()); } finally { this.setValue(value); System.out.println(value); } return value; } } static class B extends A{ public B() { super(5); setValue(getValue() - 3); } public void setValue(int value){ super.setValue(2 * value); } } }
A.11 17 34
B.22 74 74
C .6 7 7
D.22 34 17
2. After the following program is compiled and run, the result displayed on the screen is ()
public class test { public static void main(String args[]) {int x,y;x=5>>2;y=x>>>2;System.out.println(y);} }
A .0
B.2
C.5
D.80
3. There is the following code: Please write the output result of the program.
public class Test { public static void main(String[] args) { int x = 0; int y = 0; int k = 0; for (int z = 0; z < 5; z++) { if ((++x > 2) && (++y > 2) && (k++ > 2)) { x++; ++y; k++; } } System.out.println(x + ”” +y + ”” +k); } }
A.432
B.531
C.421
D.523
4. What is the result of the following code?
public class foo { public static void main(String sgf[]) { StringBuffer a=new StringBuffer(“A”); StringBuffer b=new StringBuffer(“B”); operate(a,b); System.out.println(a+”.”+b); } static void operate(StringBuffer x,StringBuffer y) { x.append(y); y=x; } }
A. The code can be compiled and run, and "AB.AB" will be output.
B. The code can be compiled and run, and "A.A" will be output.
C. The code can be compiled and run, and "AB.B" will be output.
D. The code can be compiled and run, and "A.B" will be output.
5. Given the following code, please give the result. 0608
class Two{ Byte x; } class PassO{ public static void main(String[] args){ PassO p=new PassO(); p.start(); } void start(){ Two t=new Two(); System.out.print(t.x+””); Two t2=fix(t); System.out.print(t.x+” ” +t2.x); } Two fix(Two tt){ tt.x=42; return tt; } }
A.null null 42
B.null 42 42
C.0 0 42
D.0 42 42
6. In the following code snippet, the statement with compilation error is ()
byte b1=1,b2=2,b3,b6,b8; final byte b4=4,b5=6,b7; b3=(b1+b2); /*语句1*/ b6=b4+b5; /*语句2*/ b8=(b1+b4); /*语句3*/ b7=(b2+b5); /*语句4*/ System.out.println(b3+b6);
A. Statement 2
B. Statement 1
C. Statement 3
D. Statement 4
7.What will be printed when you execute the following code? 0611
class C { C() { System.out.print("C"); } } class A { C c = new C(); A() { this("A"); System.out.print("A"); } A(String s) { System.out.print(s); } } class Test extends A { Test() { super("B"); System.out.print("B"); } public static void main(String[] args) { new Test(); } }
A.BB
B.CBB
C.BAB
D.None of the above
8. After the following code is executed, the output result is ( ) 0611
public class ClassTest{ String str = new String("hello"); char[] ch = {'a','b','c'}; public void fun(String str, char ch[]){ str="world"; ch[0]='d'; } public static void main(String[] args) { ClassTest test1 = new ClassTest(); test1.fun(test1.str,test1.ch); System.out.print(test1.str + " and "); System.out.print(test1.ch); } }
A.hello and dbc
B.world and abc
C.hello and abc
D.world and dbc
9. The following code will print out
public static void main (String[] args) { String classFile = "com.jd.". replaceAll(".", "/") + "MyClass.class"; System.out.println(classFile); }
A.com. jd
B.com/jd/MyClass.class
C.///////MyClass.class
D.com.jd.MyClass
10. For the following The code segment
class A{ public A foo(){return this;} } class B extends A{ public A foo(){ return this; } } class C extends B { _______ }
can be placed in the horizontal line position so that the program can compile and run correctly without generating errors. The option is ( )
A.public void foo(){}
B.public int foo(){return 1;}
C.public A foo(B b){return b;}
D.public A foo(){return A;}
Related articles:
Share a summary of interview questions in java
10 classic Java main method interview questions
Related videos:
The above is the detailed content of Can you do these 10 Java questions? Test your level. For more information, please follow other related articles on the PHP Chinese website!

Javaremainsagoodlanguageduetoitscontinuousevolutionandrobustecosystem.1)Lambdaexpressionsenhancecodereadabilityandenablefunctionalprogramming.2)Streamsallowforefficientdataprocessing,particularlywithlargedatasets.3)ThemodularsystemintroducedinJava9im

Javaisgreatduetoitsplatformindependence,robustOOPsupport,extensivelibraries,andstrongcommunity.1)PlatformindependenceviaJVMallowscodetorunonvariousplatforms.2)OOPfeatureslikeencapsulation,inheritance,andpolymorphismenablemodularandscalablecode.3)Rich

The five major features of Java are polymorphism, Lambda expressions, StreamsAPI, generics and exception handling. 1. Polymorphism allows objects of different classes to be used as objects of common base classes. 2. Lambda expressions make the code more concise, especially suitable for handling collections and streams. 3.StreamsAPI efficiently processes large data sets and supports declarative operations. 4. Generics provide type safety and reusability, and type errors are caught during compilation. 5. Exception handling helps handle errors elegantly and write reliable software.

Java'stopfeaturessignificantlyenhanceitsperformanceandscalability.1)Object-orientedprincipleslikepolymorphismenableflexibleandscalablecode.2)Garbagecollectionautomatesmemorymanagementbutcancauselatencyissues.3)TheJITcompilerboostsexecutionspeedafteri

The core components of the JVM include ClassLoader, RuntimeDataArea and ExecutionEngine. 1) ClassLoader is responsible for loading, linking and initializing classes and interfaces. 2) RuntimeDataArea contains MethodArea, Heap, Stack, PCRegister and NativeMethodStacks. 3) ExecutionEngine is composed of Interpreter, JITCompiler and GarbageCollector, responsible for the execution and optimization of bytecode.

Java'ssafetyandsecurityarebolsteredby:1)strongtyping,whichpreventstype-relatederrors;2)automaticmemorymanagementviagarbagecollection,reducingmemory-relatedvulnerabilities;3)sandboxing,isolatingcodefromthesystem;and4)robustexceptionhandling,ensuringgr

Javaoffersseveralkeyfeaturesthatenhancecodingskills:1)Object-orientedprogrammingallowsmodelingreal-worldentities,exemplifiedbypolymorphism.2)Exceptionhandlingprovidesrobusterrormanagement.3)Lambdaexpressionssimplifyoperations,improvingcodereadability

TheJVMisacrucialcomponentthatrunsJavacodebytranslatingitintomachine-specificinstructions,impactingperformance,security,andportability.1)TheClassLoaderloads,links,andinitializesclasses.2)TheExecutionEngineexecutesbytecodeintomachineinstructions.3)Memo


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

WebStorm Mac version
Useful JavaScript development tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Atom editor mac version download
The most popular open source editor
