- 相關(guān)推薦
富士康企業(yè)集團(tuán)招聘Java題目筆試題目
編程題:
1、繼承時候類的執(zhí)行順序問題,一般都是選擇題,問你將會打印出什么?
答:父類:
package test;
public class FatherClass
{
public FatherClass()
{
System.out.println(“FatherClass Create”);
}
}
子類:
package test;
import test.FatherClass;
public class ChildClass extends FatherClass
{
public ChildClass()
{
System.out.println(“ChildClass Create”);
}
public static void main(String[] args)
{
FatherClass fc = new FatherClass();
ChildClass cc = new ChildClass();
}
}
輸出結(jié)果:
C:>java test.ChildClass
FatherClass Create
FatherClass Create
ChildClass Create
2、內(nèi)部類的實現(xiàn)方式?
答:示例代碼如下:
package test;
public class OuterClass
{
private class InterClass
{
public InterClass()
{
System.out.println(“InterClass Create”);
}
}
public OuterClass()
{
InterClass ic = new InterClass();
System.out.println(“OuterClass Create”);
}
public static void main(String[] args)
{
OuterClass oc = new OuterClass();
}
}
輸出結(jié)果:
C:>java test/OuterClass
InterClass Create
OuterClass Create
再一個例題:
public class OuterClass {
private double d1 = 1.0;
//insert code here
}
You need to insert an inner class declaration at line 3. Which two inner class declarations are
valid?(Choose two.)
A. class InnerOne{
public static double methoda() {return d1;}
}
B. public class InnerOne{
static double methoda() {return d1;}
}
C. private class InnerOne{
double methoda() {return d1;}
}
D. static class InnerOne{
protected double methoda() {return d1;}
}
E. abstract class InnerOne{
public abstract double methoda();
}
說明如下:
一.靜態(tài)內(nèi)部類可以有靜態(tài)成員,而非靜態(tài)內(nèi)部類則不能有靜態(tài)成員,
富士康企業(yè)集團(tuán)招聘Java題目筆試題目
,資料共享平臺
《富士康企業(yè)集團(tuán)招聘Java題目筆試題目》(http://www.ishadingyu.com)。故 A、B 錯
二.靜態(tài)內(nèi)部類的非靜態(tài)成員可以訪問外部類的靜態(tài)變量,而不可訪問外部類的非靜態(tài)變量;return d1 出錯。
故 D 錯
三.非靜態(tài)內(nèi)部類的非靜態(tài)成員可以訪問外部類的非靜態(tài)變量。
故 C 正確
四.答案為C、E
3、Java 的通信編程,編程題(或問答),用JAVA SOCKET編程,讀服務(wù)器幾個字符,再寫入本地顯示?
答:Server端程序:
package test;
import java.net.*;
import java.io.*;
public class Server
{
private ServerSocket ss;
private Socket socket;
private BufferedReader in;
private PrintWriter out;
public Server()
{
try
{
ss=new ServerSocket(10000);
while(true)
{
socket = ss.accept();
String RemoteIP = socket.getInetAddress().getHostAddress();
String RemotePort = “:”+socket.getLocalPort();
System.out.println(“A client come in!IP:”+RemoteIP+RemotePort);
in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
String line = in.readLine();
System.out.println(“Cleint send is :” + line);
out = new PrintWriter(socket.getOutputStream(),true);
out.println(“Your Message Received!”);
out.close();
in.close();
socket.close();
}
}catch (IOException e)
{
out.println(“wrong”);
}
}
public static void main(String[] args)
{
new Server();
}
};
Client端程序:
package test;
import java.io.*;
import java.net.*;
public class Client
{
Socket socket;
BufferedReader in;
PrintWriter out;
public Client()
{
try
【】相關(guān)文章:
小學(xué)感恩節(jié)活動方案06-20
公司離職證明范文5篇07-11
職場人士勵志故事10-21
河南全國教師信息采集08-30
搞笑的新婚祝福語大全10-26
工作勵志格言精選08-22
服裝市場調(diào)查報告10-18
三年級蜜蜂教學(xué)反思10-25
解決問題教學(xué)反思10-29
幼兒園讀書的倡議書06-23