姓名 _______
public class Override {
①public void method(String str){};
②public void method1(String str){};
③public int method(int i){return 0;};
④public int method(double d){return 0;}
⑤public void method(String str, int i) {};
⑥public int method(){return 0;};
}
public class A {
①protected void m1() {};
②private void m2() {};
③private void m3() {};
}
class B extends A {
④public void m1() {};
⑤private void m2() {};
⑥public void m3() {};
}
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 Static {
static int a = 5;
static String s = “”;
public Static() {
calculate();
}
public static void main(String args[]){
new Static();
new Static();
new Static().show();
}
public void calculate() {
a = a + 1;
s = s + 1;
}
public void show() {
System.out.println(“a = ” + a); //输出结果:___①______
System.out.println(“s = ” + s); //输出结果:___②______
}
static {
a = a + 10;
s = s + 1;
}
}
package j2setest.access;
import j2setest.access.access1.*;
public class A extends B{
public byte i;
public A() {
}
public static void main(String args[]) {
A a = new A(); // 问题1:a包含哪些实例变量: ________________
// a能访问哪些实例变量: _______________________
C c = new C(); // 问题2:c包含哪些实例变量:________________
// c能访问哪些实例变量: ________________________
B b = new A();
A a1 = (A)b; // 问题3:此句强制转化是否正确?___________
C c2 = (C)a; // 问题4:此句强制转化是否正确?____________
}
}
class B {
public int i;
private String s;
protected double d;
B b;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////
package j2setest.access.access1;
import j2setest.access.*;
public class C extends A{
public C() {
}
}
public class BreakDemo {
public static void main(String args[]) {
for (int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
if (i == j) {
continue;
}
System.out.println(“i =” + i + ” j = ” + j);
}
}
}
}
public class BreakDemo1 {
public static void main(String args[]) {
for (int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
if (i == j) {
break;
}
System.out.println(“i =” + i + ” j = ” + j);
}
}
}
}
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) {
tail = e;
head = e;
}
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 {
obj = head.data;
head = head.next;
}
length–;
notifyAll();
return obj;
}
synchronized public Object get(int index) {
Element ptr = head;
int sequence = 0;
_______⑤______ {
wait();
}
while (ptr != null) {
if (sequence == index) {
notifyAll();
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 {
String url = request.getServletPath();
if (url.equals(“/login.do”)) {
__⑥____
___⑦___
}
else if (url.equals(“_⑧___”)) {
________⑨_____________________________________
____⑩_______
}
}
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;
}
LoginAction.java:
public class LoginAction extends Action {
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
User user = findByUserName(userName);
httpServletRequest.getSession.setAttribute(“user_right”,user);
return actionMapping.findForward(“_⑤__”);
}
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=”___⒁___________”>
⒂_____” />
web.xml
CRMWebModule
action
org.apache.struts.action.__⑴___
__⑵____
___⑶_____
http://java.sun.com/jstl/core
/WEB-INF/c.tld
__⑷____
/WEB-INF/app.tld
resource for train CRM proj
jdbc/crmdb
__⑸_____
Container
Shareable
weblogic.xml
__⑹____
mydatasource-oracle
CRMWebModule
login.jsp:
<%@ taglib uri=”__⑺______” prefix=”c” %>
<%@ tablib uri=”__⑻___” prefix=”trainCRM” %>
⑼__=”list”/>
app.tld:
1.0
1.2
Application Tag Library
http://www.umltech.net/taglibs/trainCRM
app
no
__⑽____
net.umltech.train.java.tag.AppListUserTag
_⑾____
appListUser
no
id
_⑿____
true
___⒀____
说明:
java应聘教师测试试题一答案
①
③
④
⑤
⑥
①④
①personList[i] = new Person();
②personList[i].setKids(new HashSet());
③kid.setMother(personList[i]);
④personList[i].setMother(new Mother());
⑤personList[i].getMother.setKids(new HashSet()));
⑥personList[i]
①18
②1111
问题1:a包含哪些实例变量: int i,s,d,b,byte i
a能访问哪些实例变量: int i,d,b,byte i
问题2:c包含哪些实例变量: int i,s,d,b,byte i
c能访问哪些实例变量: int i,d,byte i
问题3:此句强制转化是否正确?正确
问题4:此句强制转化是否正确?错误
第一组:
i = 0 j = 1
i = 0 j = 2
i = 1 j = 0
i = 1 j = 2
i = 2 j = 0
第二组:
i = 2 j = 1
i = 1 j = 0
i = 2 j = 0
i = 2 j = 1
①Element next;
②while(length >= MAX_LENGTH)
③notifyAll();
④wait();
⑤while(ptr == null)
①myservlet
②myserlet
③*.do
④login.do
⑤query.do
⑥ReqeustDispatcher rd = request.getRequestDispatcher(“/loginAck.jsp”);
⑦rd.forward(request,response);
⑧/query.do
⑨ReqeustDispatcher rd = request.getRequestDispatcher(“/queryAck.jsp”);
⑩response.sendDirect(“/queryAck.jsp”);
⑴loginAction.do
⑵loginForm
⑶loginForm
⑷return
⑸success
⑹group = theGroup;
⑺!found
⑻group.getRights().add(right);
⑼rs.close();
⑽pstmt.close();
⑾item
⑿${user_right.groups}
⒀item1
⒁${item.rights}
⒂${item1.rightName}
⑴ActionServlet
⑵action
⑶*.do
⑷
http://www.umltech.net/taglibs/trainCRM
⑸java.sql.DataSource
⑹ jdbc/crmdb
⑺
http://java.sun.com/jstl/core
⑻ http://www.umltech.net/taglibs/trainCRM
⑼id
⑽ appListUser
⑾empty
⑿true
⒀java.lang.String
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);
}
}