Java试题

来源:互联网 发布:轩辕剑炼妖壶进阶数据 编辑:程序博客网 时间:2024/05/16 05:55
Java试题()
1、概述struts,以及struts如何实现MVC架构的?
答:struts framework是一种基于java的技术,Web应用程序开发人员通过struts framework即可充分利用面向对象设计、代码重用以及“编写一次、到处运行”的优点。Struts提供了一种创建Web应用程序的框架,其中对应用程序的显示、表示和数据的后端代码进行了抽象。Struts采用jsp作为MVC的视图,由ActionServlet具体指定的action动作类作为控制器即MVC中的C,负责视图与模型之间的交互。控制器的每个入口点都由名为struts-config.xml的配置文件设置。该文件把来自视图的请求映射为特定的JAVA类以进行相应的处理,控制器还指定下一个视图的位置。Struts中的模型主要指的就是javabean,它是模型的代表,主要封装数据和业务逻辑。
Struts的处理流程:
l         控制器进行初始化工作,读取配置文件,为不同的Struts模块初始化相应的ModulConfig对象。
l         控制器接收Http请求,并从ActionConfig中找出对应于该请求的Action子类,如果没有对应的Action,控制器直接将请求转发给JSP或者静态页面,否则控制器将请求分发至具体的Action类进行处理。
l         在控制器调用具体的Action的Execute方法之前,ActionForm对象将利用Http请求中的参数来填充自已。还可以在ActionForm类中调用Validate方法来检查请求参数的合法性,并且可以返回一个包含所有错误信息的ActionErrors对象。
l         执行具体的的Execute的方法,它负责执行相应的业务逻辑。执行完后,返回一个ActionForward对象,控制器通过该ActionForward对象来进行转发工作。也可以把Action要处理的业务逻辑封装在JavaBean中,如果系统中还有EJB,那么通过JavaBean调用EJB以完成业务处理;如果没有EJB,那么就直接在JavaBean中连接数据库,进行数据库相关的操作。
 
2、概述MVC体系结构
答:MVC包括三类对象,model是应用对象,view是视图,controller是控制器,它定义用户界面对用户输入的响应方式。
在MVC体系中,模型通常被称为“业务逻辑”,是真正完成任务的代码,视图就是使用界面,反映数据的变化。控制器控制着模型和视图之间的交互过程,它决定着向用户返回怎样的视图、检查通过界面输入的信息以及选择处理输入信息的模型
在MVC中,表示层和逻辑层分离,各部分可相互独立进行开发,便于开发和维护,提高了开发效率。
 
3、多线程的优点
答:可分两方面来答:
l         相对于单线程而言 :
可以响应多任务的并发操作。
多线程取消了主循环和轮流检测机制,一个线程可以暂停而不阻止系统其他的部分的执行,而且当程序中一个线程阻塞时,只有那个被阻塞的线程暂停,所有其他的线程继续执行。
l         相对于进程而言:(可以答也可以不答)
它所要求的开销比较小,转换成本较小。
所有线程共享同一地址空间,相互协作。
彼此之间通信很容易。
 
4、EJB概述
答:EJB是企业级的JavaBean,它提供了构建企业级业务逻辑的一种组件模型。
    EJB分为三种:Session Bean Entity Bean Message-Driven Bean 三种,其中Session Bean分为有状态和无状态Session Bean两种,Entity Bean分为容器管理的Entity Bean ( CMP ) 和 Bean管理的 Entity Bean ( BMP )。每一个EJB由一个远程接口、一个本地接口和一个EJB容器实现组成,远程接口声明了提供给EJB客户调用的各种应用方法,本地接口声明了创建新的EJB实例的create方法、寻找EJB实例的查找(finder)方法以及刪除EJB实例的remove方法。EJB容器提供了EJB的运行环境和生命周期的管理。
5、用java访问Oracle数据库、取得记录并输出到界面
答:……………………..
   Class.forName(“oracle.jdbc.driver.OracleDriver”);
   Connection conn=DriverManager.getConnection( url , username , password );
   Statement stmt=conn.createStatement();
   String str=”select * from [table]”;
   ResultSet rs=stmt.executeQuery(str);
   While(rs.next())
   {
     ……………………
   }
   rs.close();
   stmt.close();
   conn.close();
 
6、概述java垃圾回收机制
答:它的工作原理如下:
    当不存在对一个对象的引用时,我们就假定不再需要那个对象,那个对象所占有的存储单元可以被收回,可通过System.gc()方法回收,但一般要把不再引用的对象标志为null为佳。
 
7、java类是否可以多继承,怎么实现多继承?
答:java没有多继承,但可以通过接口的形式来达到多继承的目地。
 
8、面向对象的特点
答:面向对象有三大特点:封装、继承、多态。(如果要回答四个,可加上 抽象性 这一特点)
 
9、接口有什么优点
答:接口有以下优点:
l         接口只是一个框架而没有实现,因此在接口定义时不需要考虑接口中的方法如何实现。
l         利用接口可达到实现多继承的目地。
l         可以在不暴露对象的类的前提下,暴露对象的编程接口。
l         不用强迫类关系在无关类中截获相似处(采用适配器就可以了)。
l         声明想执行的一个或多个方法。
 
10、ayList 与 Vector 的区别
答:主要从两个方面来说明:
l         安全、效率方面
如果要实现同步安全,则要用Vector,否则则用ArrayList,因为ArrayList不考虑同步安全的问题,所以效率要高些。
l         资源方面
当两者的容量已满时,它们都会自动增长其容量,但Vector是按其容量的一倍增长,而ArrayList则按其容量的50%增加,所以Vector更能节省资源。
 
11、MVC结构在Jtable中怎样实现的,这种结构有什么好处?
答、在Jtable中不存储它的单元数据,它的所有实例把它们的单元值交给实现了TableModel接口的对象来维护和管理,所以在MVC结构中,Jtable的表格主要体现了一个V的作用,其表格将数据变化体现出来,而数据模型则体现了M的作用,封装数据和业务逻辑。
       注:详细解说见第二题
 
 
12、在控制台中输入一个字符串,然后按照逆序打印出来
答:import java.io.*;
   
public class test{
       public static void main(String args[]){
    String A=””;
    String B=””;
    String C=””;
    Try{
       BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       If ((B=br.readLine())!=null){
          A=A+B;
       }
      
       for(int I=str.length()-1;I>=0;I--){
          C=C+A.substring(I,I+1);
}
System.out.println(C);
    }
    catch(Exception e){
        System.out.println(e.getMessage());
    }
}
}
 
13、java是否存在内存泄露
答:存在,当一个对象引用另一对象后,当另一对象为空时,会出现内存泄露。
 
14、String类的值是否可以改变
答:String类的值在初始后不能改变,如果要改变,可转换为StringBuffer类,这个类的值是可以动态改变的。(这里主要考String 和 StringBuffer 的区别)
 
15、Corba概述
答:通用对象请求代理,它的主要目标是解决面向对象的异构应用之间的互操作问题,并提供分布式计算所需的一些其他的服务。ORB是CORBA的核心。
    CORBA重新调整了客户与服务器之间的关系。客户可以向服务器提出事务请求,同时也可以为下一个请求充当服务器角色。由于CORBA系统引入了中间件的概念,即事件代理,由中间件完成客户机与服务器之间的通信,使得服务器对于客户机的位置相对透明,取消了原有分布式计算机模型中客户机----服务器之间的一一对应关系,CORBA客户机可以在运行时动态获得服务对象的位置,并且可以对多个服务对象提交事务请求,所以它极大的推动了分布计算的发展。另外,CORBA规范约束采用面向对象的分布式方法,以接口定义语言的形式实现对象内部细节的完整封装,从而降低了软件系统的复杂度,增加了软件功能的可重用性。CORBA提供到C C++ JAVA 等高级语言的映射,极大程度地减小了程序设计语言的依赖性。
    (有待扩展)
   
 
16、jsp的内置对象、功能以及主要方法

Jsp内置对象
功能
主要方法
out
向客户端输出数据
print() println() flush() clear() isAutoFlush() getBufferSize()   close() …………
request
向客户端请求数据
getAttributeNames() getCookies() getParameter() getParameterValues() setAttribute() getServletPath() …………..
response
封装了jsp产生的响应,然后被发送到客户端以响应客户的请求
addCookie() sendRedirect() setContentType()
flushBuffer() getBufferSize() getOutputStream()
sendError() containsHeader()……………
application
 
 
config
表示Servlet的配置,当一个Servlet初始化时,容器把某些信息通过此对象传递给这个Servlet
getServletContext() getServletName() getInitParameter()   getInitParameterNames()……………
page
Jsp实现类的实例,它是jsp本身,通过这个可以对它进行访问
flush()………
pagecontext
为JSP页面包装页面的上下文。管理对属于JSP中特殊可见部分中己经命名对象的该问
forward() getAttribute() getException() getRequest() getResponse()   getServletConfig()
getSession() getServletContext() setAttribute()
removeAttribute() findAttribute() ……………
session
用来保存每个用户的信息,以便跟踪每个用户的操作状态
getAttribute() getId()   getAttributeNames() getCreateTime() getMaxInactiveInterval()
invalidate() isNew()
exception
反映运行的异常
getMessage()…………

 
17、java 有几种修饰符?默认的是什么?
答:(注:修饰符是影响类、变量及成员方法的生存空间和可访问性的关键字)

修饰符
成员方法
成员变量
局部变量
abstract
static
public
protected
private
private protected
synchronized
native
volatile
final
transient

 
 以下是访问控制修饰符: 默认为friendly

修饰符
同类
同包
子孙类
不同包
public
protected
friendly
private

 
18、toString方法的概述
答:因为每个类都继承了Object类,所以都实现了toString()方法。
    通过toString()方法可以决定所创建对象的字符串表达形式。
 
19、Object类的概述
答:Object类是所有其他的类的超类,Object的一个变量可以引用任何其他类的对象。因为数组是作为类实现的,所以Object的一个变量也可以引用任何数组,它包括以下几种方法:
    clone() equals() finalize() getClass() hashCode() notify() notifyAll() toString() wait()
 
20、java特点
答:java具有以下几个主要特点:
l         简单性
l         面向对象:JAVA是完全面向对象的,它支持静态和动态风格的代码继承及重用
l         分布式:包括数据分布和操作分布
l         健壮性:java系统仔细检测对内存的每次访问,确认它是否合法,而且在编译和运行程序时,都要对可能出现的问题进行检查,以消除错误的产生。
l         结构中立
l         安全性:java不支持指针,一切对内存的访问都必须通过对象的实例变量来实现,这样就防止程序员使用木马等欺骗手段访问对象的私有成员,同时也避免了指针操作中容易产生的错误。
l         与平台无关:java写的应用程序不用修改就可在不同的软硬平台上运行。平台无关性有两种:源代码级和目标代码级。 Java主要靠JAVA虚拟机在目标代码级上实现平台无关性
l         解释执性:运行JAVA程序时,它首先被编译成字节代码,字节代码非常类似机器码,执行效率非常高。
l         高性能
l         多性程
l         动态性:它允许程序动态的装入运行时需要的类。
 
21、什么叫抽象类?抽象类跟接口有什么区别?为什么引进数据接口概念?
答:具有关键字abstract ,在实现内容上没有完全定义的类就叫抽象类。
抽象类和接口的区别如下:
① 在类来继承抽象类时,只需实现部分具体方法和全部抽象方法,而实现接口则要实现里面的全部方法。
②在接口中无成员变量,而抽象类中可有成员变量。
在Java中引进接口主要是为了解决多继承的问题。
 
22、doGet与doPut的区别?
答: doPut会把地址作为一个文件写到服务器,而doGet不会,而只显示在地址栏。
 
23、多线程实现有那几种方法,同步有哪几种方法?
答:实现同步主要有两种方法:1.synchronized   2.wait notify
实现多线程主要继承Thread 类和实现Runnable接口。
 
24、JSP页面的跳转?
答:jsp页面实现跳转主要有jsp:forward 和 sendRedirect 两种方法
jsp:forward:在本容器内跳转 。 跳转后,地址栏地址不变 。效率高。跳转后立即结束本页的内容。
sendRedirect:在容器之间的跳转,跳转后地址栏地址为跳转后的地址,效率较低。
通常采用jsp:forward方式跳转。
25、类变量的初始化
答:在Java中类变量在局部中一定要初始化,因为局部变量会覆盖全局变量,否则会报错:变量未初始化。全局变量则可以不初始化,而到具体的内部方法或其他的类成员中初始化。
26、数组的定义
答:数组是作为一种对象实现的。数组元素可以包含作何类型值,但数组里面的每个元素的类型必须一致创建数组步聚如下:
l         声明
l         构造
l         初始化
27、Hastable 与HashMap的区别?
答:Hashtable和Hashmap的主要区别如下:
l         Hashtable是同步的,而HashMap不是同步的。所以不要求同步的时候,用HashMap的效率较高
l         Hashtable版本较HashMap版本低。
28、说明List和Set的区别
答:两者主要区别如下:
l         List用来处理序列,而Set用来处理集。
l         List中的内容可以重复,而Set则不行。
                                  深圳某公司(四)
 
Java Text ()
1. Which of the following lines will compile without warning or error.
1) float f=1.3;
2) char c="a";
3) byte b=257;
4) boolean b=null;
5) int i=10;
 
2. What will happen if you try to compile and run the following code
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]);
    }
}
1) error Can't make static reference to void amethod.
2) error method main not correct
3) error array must include parameter
4) amethod must be declared with String
 
3. Which of the following will compile without error
1)  import java.awt.*;
package Mypackage;
class Myclass {}
2)  package MyPackage;
import java.awt.*;
class MyClass{}
3)  /*This is a comment */
package MyPackage;
import java.awt.*;
class MyClass{}
 
4. What will be printed out if this code is run with the following command line?
java myprog good morning
public class myprog{
    public static void main(String argv[])
    {
              System.out.println(argv[2]);
    }
}
1) myprog
2) good
3) morning
4) Exception raised:
 "java.lang.ArrayIndexOutOfBoundsException: 2"
  
5. What will happen when you compile and run the following code?
public class MyClass{
 static int i;
 public static void main(String argv[]){
      System.out.println(i);
 }
}
1) Error Variable i may not have been initialized
2) null
3) 1
4) 0
 
6. What will happen if you try to compile and run the following code?
public class Q {
 public static void main(String argv[]){
      int anar[]=new int[]{1,2,3};
      System.out.println(anar[1]);
 }
}
1) 1
2) Error anar is referenced before it is initialized
3) 2
4) Error: size of array must be defined
 
7. What will happen if you try to compile and run the following code?
public class Q {
 public static void main(String argv[]){
      int anar[]=new int[5];
      System.out.println(anar[0]);
 }
}
1) Error: anar is referenced before it is initialized
2) null
3) 0
4) 5
 
8. What will be the result of attempting to compile and run the following code?
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 < ar.length;i++)
      System.out.println(ar[i]);
 }
}
1) a sequence of 5 0's will be printed
2) Error: ar is used before it is initialized
3) Error Mine must be declared abstract
4) IndexOutOfBoundes Error
 
9. What will be printed out if you attempt to compile and run the following code ?
int i=1;
 switch (i) {
 case 0:
      System.out.println("zero");
      break;
 case 1:
      System.out.println("one");
 case 2:
      System.out.println("two");
 default:
      System.out.println("default");
 }
1) one
2) one, default
3) one, two, default
4) default
 
10. Which of the following lines of code will compile without error
1)  int i=0;
if(i) {
             System.out.println("Hello");
      }
2)  boolean b=true;
boolean b2=true;
if(b==b2) {
             System.out.println("So true");
      }
3) int i=1;
int j=2;
if(i==1|| j==2)
      System.out.println("OK");
4)  int i=1;
int j=2;
if(i==1 &| j==2)
             System.out.println("OK");
 
11. What will be output if you try to compile and run the following code, but there is no file called Hello.txt in the current directory?.
import java.io.*;
public class Mine
{
public static void main(String argv[])
{
              Mine m=new Mine();
              System.out.println(m.amethod());
    }
public int amethod()
{
              try
{
                  FileInputStream dis
=new FileInputStream("Hello.txt");
              }
catch (FileNotFoundException fne)
{
           System.out.println("No such file found");
           return -1;
              }
catch(IOException ioe)
{}
finally
{
                  System.out.println("Doing finally");
              }
              return 0;
    }
}
1) No such file found
2 No such file found ,-1
3) No such file found, Doing finally, -1
4) 0
12.Which of the following statements are true?
1) Methods cannot be overriden to be more private
2) static methods cannot be overloaded
3) private methods cannot be overloaded
4) An overloaded method cannot throw exceptions not checked in the base class
 
13.What will happen if you attempt to compile and run the following code?
class Base {}
class Sub extends Base {}
class Sub2 extends Base {}
public class CEx{
    public static void main(String argv[]){
       Base b=new Base();
       Sub s=(Sub) b;
    }
}
1) Compile and run without error
2) Compile time Exception
3) Runtime Exception
 
14.Which of the following statements are true?
1) System.out.println( -1 >>> 2);will output a result larger than 10
2) System.out.println( -1 >>> 2); will output a positive number
3) System.out.println( 2 >> 1); will output the number 1
4) System.out.println( 1 <<< 2); will output the number 4
 
15.What will happen when you attempt to compile and run the following code?
public class Tux extends Thread{
    static String sName = "vandeleur";
    public static void main(String argv[]){
        Tux t = new Tux();
        t.piggy(sName);
        System.out.println(sName);
      
    }
    public void piggy(String sName){
        sName = sName + " wiggy";
        start();
    }
    public void run(){
        for(int i=0;i < 4; i++){
           sName = sName + " " + i;
               
        }
    }
}
1) Compile time error
2) Compilation and output of "vandeleur wiggy"
3) Compilation and output of "vandeleur wiggy 0 1 2 3"
4) Compilation and output of either "vandeleur", "vandeleur 0", "vandeleur 0 1" "vandaleur 0 1 2" or "vandaleur 0 1 2 3"
 
16.What will be displayed when you attempt to compile and run the following code
//Code start
import java.awt.*;
public class Butt extends Frame{
    public static void main(String argv[]){
              Butt MyBut=new Butt();
    }
    Butt(){
              Button HelloBut=new Button("Hello");
              Button ByeBut=new Button("Bye");
              add(HelloBut);
              add(ByeBut);
              setSize(300,300);
              setVisible(true);
    }
}
//Code end
1) Two buttons side by side occupying all of the frame, Hello on the left and Bye on the right
2) One button occupying the entire frame saying Hello
3) One button occupying the entire frame saying Bye
4) Two buttons at the top of the frame one saying Hello the other saying Bye
 
17.What will be output by the following code?
public class MyFor{
    public static void main(String argv[]){
              int i;
              int j;
           outer:
              for (i=1;i <3;i++)
           inner:
              for(j=1; j<3; j++) {
                  if (j==2)
                     continue outer;
                  System.out.println("Value for i=" + i + " Value for j=" +j);
              }
    }
 
}
1) Value for i=1 Value for j=1
2) Value for i=2 Value for j=1
3) Value for i=2 Value for j=2
4) Value for i=3 Value for j=1
 
18.Which statement is true of the following code?
public class Agg{
public static void main(String argv[]){
              Agg a = new Agg();
              a.go();
       }
       public void go(){
              DSRoss ds1 = new DSRoss("one");
              ds1.start();
       }
}
 
class DSRoss extends Thread{
private String sTname="";
DSRoss(String s){
       sTname = s;
}
public void run(){
       notwait();
       System.out.println("finished");
}
public void notwait(){
       while(true){
              try{
                    System.out.println("waiting");
                    wait();
                     }catch(InterruptedException ie){}
              System.out.println(sTname);
              notifyAll();
              }
       }
      
}
1) It will cause a compile time error
2) Compilation and output of "waiting"
3) Compilation and output of "waiting" followed by "finished"
4) Runtime error, an exception will be thrown
 
19.Which of the following methods can be legally inserted in place of the comment //Method Here ?
class Base{
 public void amethod(int i) { }
}
 
public class Scope extends Base{
 public static void main(String argv[]){
 }
 //Method Here
}
1) void amethod(int i) throws Exception {}
2) void amethod(long i)throws Exception {}
3) void amethod(long i){}
4) public void amethod(int i) throws Exception {}
 
 
40.You have created a simple Frame and overridden the paint method as follows
public void paint(Graphics g){
g.drawString("Dolly",50,10);
}
What will be the result when you attempt to compile and run the program?
1) The string "Dolly" will be displayed at the centre of the frame
2) An error at compilation complaining at the signature of the paint method
3) The lower part of the word Dolly will be seen at the top of the frame, with the top hidden.
4) The string "Dolly" will be shown at the bottom of the frame.
 
21.What will be the result when you attempt to compile this program?
public class Rand{
    public static void main(String argv[]){
       int iRand;
       iRand = Math.random();
       System.out.println(iRand);
    }
}
1) Compile time error referring to a cast problem
2) A random number between 1 and 10
3) A random number between 0 and 1
4) A compile time error about random being an unrecognised method
 
22.Given the following code
import java.io.*;
public class Th{
    public static void main(String argv[]){
       Th t = new Th();
       t.amethod();
    }
    public void amethod(){
       try{
           ioCall();
       }catch(IOException ioe){}
    }
}
What code would be most likely for the body of the ioCall method
1) public void ioCall ()throws IOException{
 DataInputStream din = new DataInputStream(System.in);
 din.readChar();
 }
2) public void ioCall ()throw IOException{
 DataInputStream din = new DataInputStream(System.in);
 din.readChar();
 }
3) public void ioCall (){
 DataInputStream din = new DataInputStream(System.in);
 din.readChar();
 }
4) public void ioCall throws IOException(){
 DataInputStream din = new DataInputStream(System.in);
 din.readChar();
 }
 
23.What will happen when you compile and run the following code?
public class Scope{
    private int i;
    public static void main(String argv[]){
       Scope s = new Scope();
       s.amethod();
    }//End of main
    public static void amethod(){
       System.out.println(i);
    }//end of amethod
}//End of class
 
1) A value of 0 will be printed out
2) Nothing will be printed out
3) A compile time error
4) A compile time error complaining of the scope of the variable i
 
24.You want to lay out a set of buttons horizontally but with more space between the first button and the rest. You are going to use the GridBagLayout manager to control the way the buttons are set out. How will you modify the way the GridBagLayout acts in order to change the spacing around the first button?
 
1) Create an instance of the GridBagConstraints class, call the weightx() method and then pass the GridBagConstraints instance with the component to the setConstraints method of the GridBagLayout class.
2) Create an instance of the GridBagConstraints class, set the weightx field and then pass the GridBagConstraints instance with the component to the setConstraints method of the GridBagLayout class.
3) Create an instance of the GridBagLayout class, set the weightx field and then call the setConstraints method of the GridBagLayoutClass with the component as a parameter.
4) Create an instance of the GridBagLayout class, call the setWeightx() method and then pass the GridBagConstraints instance with the component to the setConstraints method of the GridBagLayout class.
 
25.Which of the following can you perform using the File class?
1) Change the current directory
2) Return the name of the parent directory
3) Delete a file
4) Find if a file contains text or binary information
 
26.Which statement is true of the following code?
public class Rpcraven{
       public static void main(String argv[]){
       Pmcraven pm1 = new Pmcraven("One");
       pm1.run();
       Pmcraven pm2 = new Pmcraven("Two");
       pm2.run();
 
       }
}
class Pmcraven extends Thread{
private String sTname="";
Pmcraven(String s){
       sTname = s;
}
public void run(){
       for(int i =0; i < 2 ; i++){
              try{
               sleep(1000);
              }catch(InterruptedException e){}
 
              yield();
              System.out.println(sTname);
              }
 
       }
}
1) Compile time error, class Rpcraven does not import java.lang.Thread
2) Output of One One Two Two
3) Output of One Two One Two
4) Compilation but no output at runtime
 
27.You are concerned that your program may attempt to use more memory than is available. To avoid this situation you want to ensure that the Java Virtual Machine will run its garbage collection just before you start a complex routine. What can you do to be certain that garbage collection will run when you want .
1) You cannot be certain when garbage collection will run
2) Use the Runtime.gc() method to force garbage collection
3) Ensure that all the variables you require to be garbage collected are set to null
4) Use the System.gc() method to force garbage collection
 
 
28Which statements about the garbage collection are true?
 
1. The program developer must create a thread to be responsible for free the memory.
2. The garbage collection will check for and free memory no longer needed.
3. The garbage collection allow the program developer to explicity and immediately free the memory.
4. The garbage collection can free the memory used java object at expect time.
 
29.You have these files in the same directory. What will happen when you attempt to compile and run Class1.java if you have not already compiled Base.java
//Base.java
package Base;
class Base{
    protected void amethod(){
       System.out.println("amethod");
    }//End of amethod
}//End of class base
package Class1;
//Class1.java
public class Class1 extends Base{
    public static void main(String argv[]){
       Base b = new Base();
       b.amethod();
    }//End of main
 
}//End of Class1
 
1) Compile Error: Methods in Base not found
2) Compile Error: Unable to access protected method in base class
3) Compilation followed by the output "amethod"
4)Compile error: Superclass Class1.Base of class Class1.Class1 not found
 
30.What will happen when you attempt to compile and run the following code
class Base{
    private void amethod(int iBase){
       System.out.println("Base.amethod");
    }
}
 
class Over extends Base{
    public static void main(String argv[]){
       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 Base.amethod is private
3) Output of "Base.amethod"
4) Output of "Over.amethod"
 
 
一个袋子中有100个黑球,100个白球,每次从中取出两个球,然后放回一个球,如果取出两个球颜色相同,则放入一个黑球,如果取出一百一黑,则放入一个白球,请问到最后袋中剩下的球的颜色:
1)黑球    2)白球    3)不一定。
给出证明。
 
建立一个数据库模型,用于管理一个公司部门及其内部雇员,每个部门都有一个负责人。根据你的数据库模型,编写sql语句建立你的数据库表,给出一个雇员的姓名,查询该雇员所属的部门负责人。