Set 28

Multiple Choice Question

QID: 
222

Given the following program, which statements are true?

// Filename: TestClass.java

public class TestClass{
public static void main(String args[]){
A[] a, a1;
B[] b;
a = new A[10]; a1 = a;
b = new B[20];
a = b; // 1
b = (B[]) a; // 2
b = (B[]) a1; // 3
}
}class A { }
class B extends A { }

Select 2 options

A. Compile time error at line 3.
B. The program will throw a java.lang.ClassCastException at the line labeled 2 when run.
C. The program will throw a java.lang.ClassCastException at the line labeled 3 when run.
D. The program will compile and run if the (B[ ] ) cast in line 2 and the whole line 3 is removed.
E. The cast at line 2 is needed.

Multiple Choice Question

QID: 
221

What will the following code snippet print?

int index = 1;
String[] strArr = new String[5];
String myStr = strArr[index];
System.out.println(myStr);

Select 1 option

A. nothing
B. null
C. It will throw ArrayIndexOutOfBounds at runtime.
D. It will print some junk value.
E. None of the above.

Multiple Choice Question

QID: 
220

Which of the following statements will correctly create and initialize an array of Strings to non null elements?

Select 4 options

A. String[] sA = new String[1] { "aaa"};
B. String[] sA = new String[] { "aaa"};
C. String[] sA = new String[1] ; sA[0] = "aaa";
D. String[] sA = {new String( "aaa")};
E. String[] sA = { "aaa"};

Multiple Choice Question

QID: 
219

Which of these array declarations and instantiations are legal?

Select 4 options

A. int[ ] a[ ] = new int [5][4] ;
B. int a[ ][ ] = new int [5][4] ;
C. int a[ ][ ] = new int [ ][4] ;
D. int[ ] a[ ] = new int[4][ ] ;
E. int[ ][ ] a = new int[5][4] ;

Multiple Choice Question

QID: 
218

What will the following code print?

int[] scores1 = { 1, 2, 3, 4, 5, 6};
int[] scores2 = { 0, 0, 0, 0, 0, 0};
   System.arraycopy(scores2, 2, scores1, 3, 2);
     for(int i : scores2) System.out.print(i);

Select 1 option

A. 123006
B. 000000
C. 000450
D. It throw an exception at run time.

Pages

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) ArrayLists (1) Arrays (2) Best Practices (12) Best Practices (Design) (3) Best Practices (Java) (7) Best Practices (Java EE) (1) BigData (3) Chars & Encodings (6) coding problems (2) Collections (15) contests (3) Core Java (All) (52) course plan (2) Database (12) Design patterns (8) dev tools (3) downloads (2) eclipse (9) Essentials (1) examples (14) Exception (1) Exceptions (4) Exercise (1) exercises (6) Getting Started (18) Groovy (2) hadoop (4) hibernate (77) hibernate interview questions (6) History (1) Hot book (4) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (7) java ee exercises (1) java ee interview questions (2) Java Elements (16) Java Environment (1) Java Features (4) java interview points (4) java interview questions (4) javajee initiatives (1) javajee thoughts (3) Java Performance (6) Java Programmer 1 (11) Java Programmer 2 (8) Javascript Frameworks (1) Java SE Professional (1) JSP (1) Legacy Java (1) linked list (3) maven (1) Multithreading (16) NFR (1) No SQL (1) Object Oriented (9) OCPJP (4) OCPWCD (1) OOAD (3) Operators (4) Overloading (2) Overriding (2) Overviews (1) policies (1) programming (1) Quartz Scheduler (1) Quizzes (17) RabbitMQ (1) references (2) resources (1) restful web service (3) Searching (1) security (10) Servlets (8) Servlets and JSP (31) Site Usage Guidelines (1) Sorting (1) source code management (1) spring (4) spring boot (3) Spring Examples (1) Spring Features (1) spring jpa (1) Stack (1) Streams & IO (3) Strings (11) SW Developer Tools (2) testing (1) troubleshooting (1) user interface (1) vxml (8) web services (1) Web Technologies (1) Web Technology Books (1) youtube (1)