设为首页 加入收藏

TOP

Java企业面试题整理集合(6)(一)
2014-11-23 22:29:26 来源: 作者: 【 】 浏览:7
Tags:Java 企业 试题 整理 集合

int il=9;


static int i2=9;


final int i3=10;


}


请 指出static 和 final所代表的含义


答案:static是指该变量为类变量,在内存中只有一份,所有该类对象共享该变量;


Final是指该变量为常量,不能被修改。



Class bbb{}


public class a{


boolean a1;


int a2;


String a3;


bbb a4;


int[] a5;


}


答案:


Class bbb{}


public class a{


boolean a1;//false;


int a2;//0


String a3;//null


bbb a4;//null


int[] a5;//null


}



public class MyClass{


public static void main(String arguments[]){


amethod(arguments);


}


public void amethod(String[] arguments){


System.out.println(arguments);


System.out.println(arguments[1]);


}


}


答案:在静态方法中不能调用非静态方法和属性。


两种改法:要么把amethod()声明为static,要么在main方法中构造MyClass对象,由MyClass对象调用amethod()方法。



答案:public指该变量可以被所有其他对象访问;protected指该变量只能被继承类访问;private指该变量只能被本类对象访问。



abstract class MineBase{


abstract void amethod();


static int I ;


}


public class Mine extends MineBase{


public static void main(String argv[]){


int[] ar=new int[5];


for(i=0;i

System.out.println(ar[i]);


}


}


答案:Mine是MineBase的子类,要么实现MineBase的抽象方法amethod(),要么把自己声明为abstract。



答案:用来管理UI界面对象布局的。


常见的有FlowLayout、GridLayout等。



1)The ActionListener interface has no corresponding Adapter class


2) The processing of an event listener requires a try/catch block


3) If multiple listeners are added to a component only events for the last listener added will be processed


4) If multiple listeners are added to acomponent the events will be processed for all but with no guarantee in the order


答案:3



1) A class may extend only one other class and implement only one interface


2) interfaces are the Java approach to addressing its lack of multiple inheritance but require implementing classes to create the functionality of the Interfaces.


3) All of the variables in an interface are implicitly static and final


4) All of the methods in an interface are implicitly abstract


答案:2、3、4



interface Iface{}


Class Cface implements Iface{}


Class Base{};


Public class ObRef extends Base{


ObRef ob=new ObRef();


Base b=new Base();


Object o1=new Object();


Iface o2=new Cface();


}



1)o1=o2;


2)b=ob;


3)ob=b;


4)o1=b;


答案:1、2、4



1) At the root of the collection hierarchy is a class called Collection


2) The collection interface contains a method called enumerator


3) The interator method returns an instance of the Vector class


4) The set interface is designed for unique elements


答案:4



public String statement(){


String =””;


for(int i=0;i<500;i++)


s+=Item[i];


return s;


}


答案:String的连接操作(+=)会产生很多对象,性能不好


public String statement(){


StringBuffer buffer = new StringBuffer();


for(int i=0;i<500;i++)


buffer.append(Item[i].toString());


return buffer.toString();


}



try{


Statement sm = con.createStatement();


ResultSet rs=sm.execQuery(“SQL字符串”);


int i=rs.getInt(1);


//其它语句


rs.close();


sm.close();


}catch(SQLException e){


处理程序


}


答案:数据库的释放应该在finnaly块中


Statement sm = null;


ResultSet rs = null;


try{


m = con.createStatement();


rs=sm.execQuery(“SQL字符串”);


int i=rs.getInt(1);


//其它语句


}catch(SQLException e){


处理程序


}finally{


try{


if(rs != null && !rs.isClosed()){


rs.close();


}


}catch(Exception ex){


rs = null;


}


try{


if(sm != null){


sm.close();


}


}catch(Exception ex){


sm = null;


}


}



那么java bbb.class 会运行成功吗?如果不能运行话,什么原因?


答案:能够正确运行。



class Base{


private void amethod (int iBase){


System.out.println(“Base.amethod”);


}


}


class Over extends Base{


public static void main(String vrgv[]){


Over o=new Over();


int iBase=0;


o.amethod(iBase);


}


public void amethod(int iOver){


System.out.println(“Over.amethod”);


}


}


1)Compile time error complaining that Base amethod is private


2)Runtime error complaining that Ba

首页 上一页 1 2 3 下一页 尾页 1/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇什么是冒烟测试(Smoke Test)? 下一篇网络工程师面试(三木通信技术有限..

评论

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