设为首页 加入收藏

TOP

java应聘教师测试试题二
2014-11-07 10:15:04 来源: 作者: 【 】 浏览:16
Tags:java 应聘 教师 测试 试题

注意:


考试时间:120分钟


请将答案写在答题纸上,写在试卷上不作批改,视无效处理。本试卷共计10题。


public class A {


public static void method(String str){};


protected int method(int i){return 0;};


private void method(String str, int i) {};


public int method(){return 0;};


⑤void method(A a){};


}


class B extends A {


public static void method(String str) {};


⑦public int method(int i) {return 0;};


⑧public void method(String str,int i) {};


⑨int method() {return 0;};


⑩public method(A a) {};


}


public class ObjectArray {


public static void main(String args[]) {


Person personList[] = new Person[4];


for (int i = 0; i < personList.length; i++) {


_ __


personList[i].setId(“id ” + i);


personList[i].setName(“name ” + i);


____


for (int j=0; j < 2;j++){


Person kid = new Person();


kid.setId(“kid id” + j);


kid.setName(“kid name” + j);


____


personList[i].getKids().add(kid);


}


____


personList[i].getMother().setId(“mother id”);


personList[i].getMother().setName(“mother name”);


____


personList[i].getMother().getKids().add(_____);


}


}


}


class Person {


private String id;


private String name;


HashSet kids;//子女


Person mother;//母亲


// setter 和 getter 方法省略。


}


public class A {


protected static int i = 10;


protected static String s = “”;


private static A a;


//写出A的构造函数


___



public static void main(String[] args) {


A a = null;


System.out.println(a.i); //输出结果:____


a = A.getInstance();


System.out.println(a.s); //输出结果:____


}



// 写出方法getInstance()的定义。


__④__



static {


i += 10;


s += 10;


a = new A();


}


}


package j2setest.access;


import j2setest.access.access1.*;



public class A extends B{


public byte i = 1;


public A() {


}


public void test() {System.out.println(“In A”);}


public static void main(String args[]) {


A a = new A(); // a包含哪些实例变量: ____


// a能访问哪些实例变量: ____


C c = new C(); // c包含哪些实例变量:______


// c能访问哪些实例变量: ____


B b = new A();


A a1 = (A)b; // 此句强制转化是否正确?____


C c2 = (C)a; // 此句强制转化是否正确?_____


b.test(); // 打印结果________________


System.out.println(b.i); //打印结果__________


}


}



class B {


public int i = 5;


private String s;


protected double d;


B b;


public void test(){System.out.println(“In B”);}


}


//////////////////////////////////////////////////////////////////////////////////////////////////////////


package j2setest.access.access1;


import j2setest.access.*;



public class C extends A{


public C() {


}


public void test() {System.out.println(“In C”);};


}


public class MyList {


private Element head=null;


private Element tail = null;


private int length=0;


private static final int MAX_LENGTH = 1024;



class Element {


Object data;


____;


Element(Object data) {


this.data = data;


}


}



synchronized public void addElement(Object d)


{


Element e = new Element(d);


if (length == 0) {


_____;


_____;


}


else {


_____ {


wait();


}


e.next = null;


tail.next = e;


tail = e;


}


length++;


_⑤_


}



synchronized public Object removeElement() {


Object obj;


while (length == 0 ) {


_____;


}


else if (length == 1) {


obj = head.data;


head = tail = null;



}


else {


_____;


_______;



}


length–;


notifyAll();


return obj;


}



synchronized public Object get(int index) {


Element ptr = head;


int sequence = 0;



_____ {


wait();


}


while (ptr != null) {


if (sequence == index) {


___;


return ptr.data;


}


ptr = ptr.next;


sequence++;


}


notfiyAll();


return null;


}



}


web.xml:



_________


net.umltech.train.java.test.MyServlet




__________


___________




login.jsp:


④________”>




query.jsp:


⑤_______”>




MyServlet.java:


public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


_______);


if (url.equals(“/login.do”)) {


_____


______


}


else if (url.equals(“/query.do”)) {


______


______


}


}


login.jsp:


①__”>




struts-config.xml:



②___” type=”net.umltech.train.form.LoginForm” />




③__” path=”/loginAction” scope=”session” type=”net.umltech.train.action.LoginAction”>






User.java:


public class User{


private String userId;


private String userName;


private Set groups = new HashSet();


//getter,setter method are omitted.


}


Group.java:


public class Group{


private String groupId;


private String groupName;


private Set rights = new HashSet();


// getter,setter method are omitted.


boolean equals(Group group) {


__④__


}


}



Right.java:


public class Right{


private String rightId;


private String rightName;


}


写出数据库中和User,Group,Right类分别对应的users,groups和rights表的定义:_______


LoginAction.java:


public class LoginAction extends Action {


public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {


try {


User user = findByUserName(actionForm.getUserName());


httpServletRequest.getSession.setAttribute(“user_right”,user);


} catch(Exception e) {}


return actionMapping.findForward(“success”);


}



public User findByUserName(String userName) throws Exception{


String mysql =


“select users.USER_ID,groups.GROUP_ID,groups.NAME,rights.RIGHT_ID,rights.NAME


from users,user_group,groups,group_right,rights where users.NAME =


and users.USER_ID = user_group.USER_ID


and user_group.GROUP_ID = groups.GROUP_ID


and groups.GROUP_ID = group_right.GROUP_ID


and group_right.RIGHT_ID = rights.RIGHT_ID”;


PreparedStatement pstmt = connection.PrepareStatement(mysql);


pstmt.setString(1,userName);


ResultSet rs = pstmt.executeQuery();


User user = new User();


while(rs.next()) {


String userId = rs.getString(1);


String groupId = rs.getString(2)


String groupName =rs.getString(3);


String rightId = rs.getString(4);


String rightName = rs.getString(5);



Group group = new Group();


group.setGroupId(groupId);


group.setGroupName(groupName);



Set groups = user.getGroups();


iterator iter = groups.iterator();


boolean found = false;


while(iter.hasNext()) {


Group theGroup = (Group)iter.next();


if (theGroup.equals(group)) {


_______


found=true;


break;


}


}


if (______) {


groups.add(group);


}



Right right = new Right();


right.setRightId(rightId);


right.setRightName(rightName);


____________


} // while(rs.next())


_____


_____


connection.close();


return user;


}// findByUsername


}



success.jsp:将用户的组权限的名称显示出来:


⑾___” items=”________”>


⒀____” items=”_______”>


⒂____” />




程序说明:类DynArray实现了一个动态数组。当数组的空间不够时动态分配空间。


public class DynArray {


private Object[] array;


private int index;


public DynArray() {


array = new Object[16];


index = -1;


}


// 向动态数组中添加一个对象obj。如果空间不够,重新分配空间。


public void add(Object obj) {


if (index == array.length -1) {


__


__


__


}


array[++index] = obj;


}


//从数组中删除一个指定对象。


public void remove(Object obj) {


if (index < 0) {


return;


}


for (int i = 0; i <= index; i++) {


if (array[i].equals(obj)) {


for (int j = i; j < index; j++) {


____


}


break;


}


}


index–;


}


//返回指定索引处的对象。


public Object getAt(int index) {


return array[index];


}


//返回当前数组的元素个数。


public int size() {


return index + 1;


}


}


//接口MySet定义一个集合操作


import java.util.Iterator;


public interface MySet {


public boolean put(Object obj);


public boolean remove(Object obj);


public Iterator iter();


public boolean contains(Object obj);


}


//类MyHashSet采用哈希表来存储集合元素


public class MyHashSet implements MySet {


private DynArray[] container;


private int count;



public MyHashSet() {


count = 0;


container = new DynArray[16];


}


//向集合中添加一个元素,但不允许重复元素,否则返回false。成功则返回true;


public boolean put(Object obj) {


if (contains(obj)) {


return false;


}


int hashCode = Math.abs(obj.hashCode());


int pos = ___________;


if (container[pos] == null) {


___________;


}


__________;


count++;


return true;


}


//从集合中删除一个元素,当集合中没有该元素时返回false。成功删除返回true;


public boolean remove(Object obj) {


if (!contains(obj)) {


return false;


}


int hashCode = Math.abs(obj.hashCode());


int pos = hashCode % container.length;


_________;


count–;


return true;


}


// 返回一个集合的迭代器


public Iterator iter() {


_________


}


// 判断集合中是否包括指定的元素。


public boolean contains(Object obj) {


Iterator iter = new MyIterator();


while (iter.hasNext()) {


Object theObj = iter.next();


if (theObj.equals(obj)) {


return true;


}


}


return false;


}


//一个实现标准Iterator接口的内部类。


class MyIterator implements Iterator {


private int containerIndex = 0;


private int iterCount = 0;


private int arrayIndex = 0;



public void remove() {


}



public boolean hasNext() {


if (_________) {


return true;


}


else {


return false;


}


}



public Object next() {


Object obj = null;


while (containerIndex < container.length) {


if (container[containerIndex] == null) {


containerIndex++;


continue;


}


if (arrayIndex < container[containerIndex].size()) {


obj = _______________


arrayIndex++;


iterCount++;


break;


}


else {


containerIndex++;


arrayIndex = 0;


_________


}


}


return obj;


}


}


}




说明:


写出各个类、接口的定义,包括实例变量的定义,方法的定义和方法的示例性实现。



参考答案:


java应聘教师测试试题二答案



前40题正确,后20题错误。


3.


4.


5.


6.


7.


8.


9:


10.


将此题答案写在第二页答题纸的反面。


public abstract class Vehicle {


private Engine engine;


public Vehicle() {


}


public void setEngine(Engine engine) {


this.engine = engine;


}


public abstract String go();


public void startEngine() {


if (this.engine != null) {


this.engine.start();


}


}


public void stopEngine() {


if (this.engine != null) {


this.engine.stop();


}


}


public boolean isEngineOn() {


if (this.engine != null) {


return this.engine.isOn();


}


return false;


}


}



public class Car extends Vehicle{


public Car() {


}


public String go() {


if (this.isEngineOn()) {


return “!!!!”;


}


else {


return “…”;


}


}


}



public interface CargoTransport {


public void loadCargo();


}


public class Truck extends Vehicle implements CargoTransport {


public Truck() {


}


public String go() {


if (this.isEngineOn()) {


return “!!!”;


}


else {


return “…”;


}


}


public void loadCargo() {


System.out.println(“truck can load cargo.”);


}



}



public class Engine {


private boolean on;


public Engine() {


}


public void start() {


this.on = true;


}


public void stop() {


this.on = false;


}


public boolean isOn() {


return this.on;


}


}



public class Person {


private Vector vehicles = new Vector();


public Person() {


}


public void addVehicle(Vehicle v) {


vehicles.addElement(v);


}


}



】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇中兴软创面试测试题 下一篇中兴Java 数据库 Web开发笔试题 J..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: