JAVA \u8b49\u7167\u8a66\u984c.docx - Ex.1 Int]array2D system.out.print system.out.print = cfw_0,1,2,cfw_3,4,5,6(array2D[0.length(array2D[1]getClass.isArray

JAVA u8b49u7167u8a66u984c.docx - Ex.1 Int]array2D...

This preview shows page 1 - 7 out of 82 pages.

Ex.1Int[][]array2D={{0,1,2},{3,4,5,6}};system.out.print(array2D[0].length+””);system.out.print(array2D[1]getClass().isArray()+”);system.out.println (array2D[0][1]) ;Whatistheresult? A.3false1B.2true3C.2false3D.3ture1E.3false3F.2true1G.2false1Ans : DEx.2View the exhibit:public class Student{public String name = “ ” ;public int age = 0 ;public String major = “Undeclared” ;public Boolean fulltime = true ;public void display( ){System.out.println(“Name:”+name+” Major: ” + major) ;}public boolean isFullTime(){return fulltime ;}}
Image of page 1
Given:public class TestStudent{public static void main(String[] args){Student bob = new Student ( );Student jian = new Student ( );bob.name = “Bob” ;bob.name = 19 ;jian = bob ;jian.name = “Jian” ;System .out.println(“Bob’s Name: ” + bob.name);}}What is the result when this program is executed.? Ex.3Given the cade fragment:String valid = “ true”;if (valid)System.out.println(“valid”);else system.out.println(“not valid”) ;What is the result?
Image of page 2
Ex.4public class ScopeTest {int z ;public static void main(String[] args){Scopetest myScope = new Scopetest() ;int z = 6 ;System.out.println(z);myScope.doStuff();System.out.println(z);System.out.println(myScope.z);}void doStuff( ){int z = 5 ;doStuff2( );System.out.println(z) ;}void doStuff2(){z = 4 ;}}What is the result?
Image of page 3
Ex.5Which two are valid instantiations and initializations of a multidimensionalarray ? A.int[ ][ ] array2D ={{0,1,2,4}{5,6}} ;B.int [ ][ ] array2D = new int [2] [2] ;array2D[0] [0] = 1 ; array2D[0] [1] = 2 ; array2D[1] [0] = 3 ; array2D[1] [1] = 4 ; C.int [ ][ ][ ] array3D = {{0,1},{2,3},{4,5}} ;D.int [ ][ ][ ] array3D = new int [2] [2] [2] ;int [ ]array = new int [2] ;array3D [0][0] = array ; array3D [0][1] = array ;array3D [1][0] = array ;array3D [0][1] = array ;E.int [] []array2D = {0,1} ;Ans: B , D Ex.6An unchecked exception occurs in a method dosomething( ).Should other code beadded in the dosomething( ) method for it to compile and execute? Ans:D
Image of page 4
Ex.7Given the code fragment :int b = 4 ;b- -;System.out.println (- -b) ;System.out.println(b) ;What is the result/A. Given the code fragment:interface SampleCloseable{public void close ( ) throws java.io.IOException;}which implementation is valid?
Image of page 5
Image of page 6
Image of page 7

You've reached the end of your free preview.

Want to read all 82 pages?

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture