富士康企業集團招聘Java题目笔试题目
编程题:
1、继承时候类的执行顺序问题,一般都是选择题,问你将会打印出什么?
答:父类:
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();
}
}
输出结果:
C:>java test.ChildClass
FatherClass Create
FatherClass Create
ChildClass Create
2、内部类的实现方式?
答:示例代码如下:
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();
}
}
输出结果:
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();
}
说明如下:
一.静态内部类可以有静态成员,而非静态内部类则不能有静态成员,
富士康企業集團招聘Java题目笔试题目
,资料共享平台
《富士康企業集團招聘Java题目笔试题目》(https://www.unjs.com)。故 A、B 错
二.静态内部类的非静态成员可以访问外部类的静态变量,而不可访问外部类的`非静态变量;return d1 出错。
故 D 错
三.非静态内部类的非静态成员可以访问外部类的非静态变量。
故 C 正确
四.答案为C、E
3、Java 的通信编程,编程题(或问答),用JAVA SOCKET编程,读服务器几个字符,再写入本地显示?
答: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
【富士康企業集團招聘Java题目笔试题目】相关文章:
2.JAVA笔试题目
3.名企笔试题目
7.校园招聘笔试题目