Lara Technologies Special-Six Test

Similar documents
1.Which four options describe the correct default values for array elements of the types indicated?

SECTION-1 Q.1.Which two code fragments are most likely to cause a StackOverflowError? (Choose two.)

d. If a is false and b is false then the output is "ELSE" Answer?

Module 4 - 异常和断言 一 选择题 :

Sun Certified Programmer for Java 2 Platform 1.4. Version 3.0

Vendor: Oracle. Exam Code: 1Z Exam Name: Java SE 8 Programmer. Version: Demo

1. Short circuit AND (&&) = if first condition is false then the second is never evaluated

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

AP COMPUTER SCIENCE A

For more details on SUN Certifications, visit

C212 Early Evaluation Exam Mon Feb Name: Please provide brief (common sense) justifications with your answers below.

I pledge by honor that I will not discuss this exam with anyone until my instructor reviews the exam in the class.

CMPS 12A - Winter 2002 Midterm 2 March 5, Name: ID:

ITCertMaster. Safe, simple and fast. 100% Pass guarantee! IT Certification Guaranteed, The Easy Way!

Chapter 1: Introduction to Computers, Programs, and Java

COE318 Lecture Notes Week 10 (Nov 7, 2011)

1. Find the output of following java program. class MainClass { public static void main (String arg[])

JAVA OPERATORS GENERAL

Selenium Class 9 - Java Operators

King Saud University College of Computer and Information Sciences Computer Science Department

CIS 1068 Program Design and Abstraction Spring2016 Midterm Exam 1. Name SOLUTION

Day 2 : Intermediate Concepts 1 Examples

Birkbeck (University of London) Software and Programming 1 In-class Test Mar 2018

Prof. Navrati Saxena TA: Rochak Sachan

WOSO Source Code (Java)

Java Programming for Selenium

Some Practice Midterm Problems

Operators Questions

Spring University of New Mexico CS152 Midterm Exam. Print Your Name

C16b: Exception Handling

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

Motivating Examples (1.1) Selections. Motivating Examples (1.2) Learning Outcomes. EECS1022: Programming for Mobile Computing Winter 2018

CSC Java Programming, Fall Java Data Types and Control Constructs

Module 1-JAVA 基础 一 选择题 :

Fundamentals of Object Oriented Programming

Oracle 1Z Java SE 8 Programmer I. Download Full Version :

CHETTINAD COLLEGE OF ENGINEERING & TECHNOLOGY JAVA

1.00 Introduction to Computers and Engineering Problem Solving. Quiz 1 March 7, 2003

Term 1 Unit 1 Week 1 Worksheet: Output Solution

A Third Look At Java. Chapter Seventeen Modern Programming Languages, 2nd ed. 1

Following is the general form of a typical decision making structure found in most of the programming languages:

More on Exception Handling

Section 003 Fall CS 170 Exam 2. Name (print): Instructions:

CIS October 19, 2017

Name Section Number. Sections 1-3 *** TURN OFF ALL ELECTRONIC DEVICES*** Bob Wilson

CSE 8B Final Exam Fall 2015

CMSC131. Exceptions and Exception Handling. When things go "wrong" in a program, what should happen.

King Saud University College of Computer and Information Sciences Computer Science Department

WES-CS GROUP MEETING #9

CIS265 - Spring Exam 2 First Name Last Name CSU#

For that purpose, java provides control structures that serve to specify what has to be done by our program, when and under which circumstances.

Programming Basics. Digital Urban Visualization. People as Flows. ia

EXCEPTION HANDLING. // code that may throw an exception } catch (ExceptionType parametername) {

Java Simple Data Types

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

Computer Programming, I. Laboratory Manual. Final Exam Solution

Selections. EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG

Topic 6: Exceptions. Exceptions are a Java mechanism for dealing with errors & unusual situations

Chapter 8. Exception Handling. CS 180 Sunil Prabhakar Department of Computer Science Purdue University

Tutorial # 4. Q1. Evaluate the logical (Boolean) expression in the following exercise

CMPS 12A Winter 2006 Prof. Scott A. Brandt Final Exam, March 21, Name:

University of Palestine. Mid Exam Total Grade: 100

Tutorial 06. Conditional statement: if then, if else, switch


More on Exception Handling

Full file at Chapter 2 - Inheritance and Exception Handling

Java certification success, Part 1: SCJP

public class Test { static int age; public static void main (String args []) { age = age + 1; System.out.println("The age is " + age); }

CS 177 Spring 2010 Exam I

CIS October 16, 2018

Midterm Exam CS 251, Intermediate Programming March 12, 2014

Getting started with Java

CIS 120 Programming Languages and Techniques. Midterm II. November 12, 2010

CS115. Chapter 17 Exception Handling. Prof. Joe X. Zhou Department of Computer Science. To know what is exception and what is exception handling

PASS4TEST. IT Certification Guaranteed, The Easy Way! We offer free update service for one year

CS 102 / CS Introduction to Programming Midterm Exam #1 - Prof. Reed Fall 2010

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

DM550 / DM857 Introduction to Programming. Peter Schneider-Kamp

AP Computer Science Midterm Review Part 1

CIS March 1, 2018

CS 113 PRACTICE FINAL

CPSC 219 Extra review and solutions

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

COE 212 Engineering Programming. Welcome to Exam II Thursday April 21, Instructors: Dr. Salim Haddad Dr. Joe Tekli Dr. Wissam F.

1. Java is a... language. A. moderate typed B. strogly typed C. weakly typed D. none of these. Answer: B

Practice Questions for Chapter 9

Repetition with for loops

CS 200 Command-Line Arguments & Exceptions Jim Williams, PhD

Java Control Statements

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

CMPS 12A - Winter 2002 Final Exam A March 16, Name: ID:

Exam Questions 1z0-853

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

Happy Cinco de Mayo!!!!

Date: Dr. Essam Halim

COMP-202 Unit 9: Exceptions

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

Faculty of Science COMP-202A - Foundations of Computing (Fall 2013) - All Sections Midterm Examination

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

Transcription:

Flow control Part-1 Q: 01 Given: 10. public class Bar 11. static void foo( int... x ) 12. // insert code here 13. 14. Which two code fragments, inserted independently at line 12, will allow the class to compile? (Choose two.) A. foreach( x ) System.out.println(z); B. for( int z : x ) System.out.println(z); C. while( x.hasnext() ) System.out.println( x.next() ); D. for( int i=0; i< x.length; i++ ) System.out.println(x[i]); Q: 02 Click the Task button.

Q: 03 Given: 25. int x = 12; 26. while (x < 10) 27. x--; 28. 29. System.out.print(x); What is the result? A. 0 B. 10 C. 12 D. Line 29 will never be reached. Q: 04 Given: 11. public static void main(string[] args) 12. Object obj = new int[] 1, 2, 3 ; 13. int[] somearray = (int[])obj; 14. for (int i : somearray) System.out.print(i + " "); 15. What is the result? A. 1 2 3 B. Compilation fails because of an error in line 12. C. Compilation fails because of an error in line 13. D. Compilation fails because of an error in line 14. E. A ClassCastException is thrown at runtime. Q: 05 Given: 11. public static void main(string[] args) 12. for (int i = 0; i <= 10; i++) 13. if (i > 6) break; 14. 15. System.out.println(i); 16. What is the result? A. 6 B. 7 C. 10 D. 11 E. Compilation fails. F. An exception is thrown at runtime.

Q: 06 Given: 11. public static void main(string[] args) 12. Integer i = new Integer(1) + new Integer(2); 13. switch(i) 14. case 3: System.out.println("three"); break; 15. default: System.out.println("other"); break; 16. 17. What is the result? A. three B. other C. An exception is thrown at runtime. D. Compilation fails because of an error on line 12. E. Compilation fails because of an error on line 13. F. Compilation fails because of an error on line 15. Q: 07 Given: 10. public class ClassA 11. public void count(int i) 12. count(++i); 13. 14. And: 20. ClassA a = new ClassA(); 21. a.count(3); Which exception or error should be thrown by the virtual machine? A. StackOverflowError B. NullPointerException C. NumberFormatException D. IllegalArgumentException E. ExceptionInInitializerError Q: 08 Given: 35. int x = 10; 36. do 37. x--; 38. while (x < 10); How many times will line 37 be executed? A. ten times B. zero times

C. one to nine times D. more than ten times 9. Given the following code: public class OrtegorumFunction public int computediscontinuous(int x) int r = 1; r += x; if ((x > 4) && (x < 10)) r += 2 * x; else (x <= 4) r += 3 * x; else r += 4 * x; r += 5 * x; return r; public static void main(string [] args) OrtegorumFunction o = new OrtegorumFunction(); System.out.println("OF(11) is: " + o.computediscontinuous(11)); What is the result? A. OF(11) is: 45 B. OF(11) is: 56 C. OF(11) is: 89 D. OF(11) is: 111 E. Compilation fails. F. An exception is thrown at runtime. 10. Given: 1. class Crivitch 2. public static void main(string [] args) 3. int x = 0; 4. // insert code here 5. do while (x++ < y); 6. System.out.println(x); 7. 8. Which, inserted at line 4, produces the output 12?

A. int y = x; B. int y = 10; C. int y = 11; D. int y = 12; E. int y = 13; F. None of the above will allow compilation to succeed. 11. Given: class Swill public static void main(string[] args) String s = "-"; switch(timezone.cst) case EST: s += "e"; case CST: s += "c"; case MST: s += "m"; default: s += "X"; case PST: s += "p"; System.out.println(s); enum TimeZone EST, CST, MST, PST What is the result? A. -c B. -X C. -cm D. -cmp E. -cmxp F. Compilation fails. G. An exception is thrown at runtime. 12. Given: class Circus public static void main(string[] args) int x = 9; int y = 6; for(int z = 0; z < 6; z++, y--) if(x > 2) x--; label: if(x > 5)

System.out.print(x + " "); --x; continue label; x--; What is the result? A. 8 B. 8 7 C. 8 7 6 D. Compilation fails. E. An exception is thrown at runtime. 13. Given: 1. class Loopy 2. public static void main(string[] args) 3. int[] x = 7,6,5,4,3,2,1; 4. // insert code here 5. System.out.print(y + " "); 6. 7. Which, inserted independently at line 4, compiles? (Choose all that apply.) A. for(int y : x) B. for(x : int y) C. int y = 0; for(y : x) D. for(int y=0, z=0; z<x.length; z++) y = x[z]; E. for(int y=0, int z=0; z<x.length; z++) y = x[z]; F. int y = 0; for(int z=0; z<x.length; z++) y = x[z]; 14. Given: 1. class Ring 2. final static int x2 = 7; 3. final static Integer x4 = 8; 4. public static void main(string[] args) 5. Integer x1 = 5; 6. String s = "a"; 7. if(x1 < 9) s += "b"; 8. switch(x1)

9. case 5: s += "c"; 10. case x2: s += "d"; 11. case x4: s += "e"; 12. 13. System.out.println(s); 14. 15. What is the result? A. abc B. abcde C. Compilation fails due only to an error on line 7. D. Compilation fails due only to an error on line 8. E. Compilation fails due only to an error on line 10. F. Compilation fails due only to an error on line 11. G. Compilation fails due to errors on multiple lines. Part-2 1) public void foo( boolean a, boolean b) if( a ) System.out.println("A"); /* Line 5 */ else if(a && b) /* Line 7 */ System.out.println( "A && B"); else /* Line 11 */ if (!b ) System.out.println( "notb") ; else System.out.println( "ELSE" ) ; A. If a is true and b is true then the output is "A && B" B. If a is true and b is false then the output is "notb" C. If a is false and b is true then the output is "ELSE" D. If a is false and b is false then the output is "ELSE" 2) int i = l, j = -1;

switch (i) case 0, 1: j = 1; /* Line 4 */ case 2: j = 2; default: j = 0; System.out.println("j = " + j); A. j = -1 B. j = 0 C. j = 1 D. Compilation fails. 3) public class Switch2 final static short x = 2; public static int y = 0; public static void main(string [] args) for (int z=0; z < 3; z++) switch (z) case x: System.out.print("0 "); case x-1: System.out.print("1 "); case x-2: System.out.print("2 "); A. 0 1 2 B. 0 1 2 1 2 2 C. 2 1 0 1 0 0 D. 2 1 2 0 1 2

4) public void test(int x) int odd = 1; if(odd) /* Line 4 */ System.out.println("odd"); else System.out.println("even"); Which statement is true? A. Compilation fails. B. "odd" will always be output. C. "even" will always be output. D. "odd" will be output for odd values of x, and "even" for even values. 5) public class While public void loop() int x= 0; while ( 1 ) /* Line 6 */ System.out.print("x plus one is " + (x + 1)); /* Line 8 */ A. There is a syntax error on line 1. B. There are syntax errors on lines 1 and 6 C. There are syntax errors on lines 1, 6, and 8. D. There is a syntax error on line 6.

6) int i = 1, j = 10; do if(i > j) break; j--; while (++i < 5); System.out.println("i = " + i + " and j = " + j); A. i = 6 and j = 5 B. i = 5 and j = 5 C. i = 6 and j = 4 D. i = 5 and j = 6 7) boolean bool = true; if(bool = false) /* Line 2 */ System.out.println("a"); else if(bool) /* Line 6 */ System.out.println("b"); else if(!bool) /* Line 10 */ System.out.println("c"); /* Line 12 */ else System.out.println("d");

A. a B. b C. c D. d 8) public class If1 static boolean b; public static void main(string [] args) short hand = 42; if ( hand < 50 &!b ) /* Line 7 */ hand++; if ( hand > 50 ); /* Line 9 */ else if ( hand > 40 ) hand += 7; hand++; else --hand; System.out.println(hand); A. 41 B. 42 C. 50 D. 51

9) for (int i = 0; i < 4; i += 2) System.out.print(i + " "); System.out.println(i); /* Line 5 */ A. 0 2 4 B. 0 2 4 5 C. 0 1 2 3 4 D. Compilation fails. 10) public class Delta static boolean foo(char c) System.out.print(c); return true; public static void main( String[] argv ) int i = 0; for (foo('a'); foo('b') && (i < 2); foo('c')) i++; foo('d'); A. ABDCBDCB B. ABCDABCD C. Compilation fails D. An exception is thrown at runtime.

Part-3 1 ) for(int i = 0; i < 3; i++) switch(i) case 0: break; case 1: System.out.print("one "); case 2: System.out.print("two "); case 3: System.out.print("three "); System.out.println("done"); A. done B. one two done C. one two three done D. one two three two three done 2) public class Switch2 final static short x = 2; public static int y = 0; public static void main(string [] args) for (int z=0; z < 4; z++) switch (z) case x: System.out.print("0 "); default: System.out.print("def "); case x-1: System.out.print("1 "); break; case x-2: System.out.print("2 "); A. 0 def 1 B. 2 1 0 def 1 C. 2 1 0 def def

D. 2 1 0 def 1 def 1 3) public class Outer public void someoutermethod() //Line 5 public class Inner public static void main(string[] argv) Outer ot = new Outer(); //Line 10 Which of the following code fragments inserted, will allow to compile? A. new Inner(); //At line 5 B. new Inner(); //At line 10 C. new ot.inner(); //At line 10 D. new Outer.Inner(); //At line 10 4) Float f = new Float("12"); switch (f) case 12: System.out.println("Twelve"); case 0: System.out.println("Zero"); default: System.out.println("Default"); A. Zero B. Twelve

C. Default D. Compilation fails 5) public void test(int x) int odd = 1; if(odd) /* Line 4 */ System.out.println("odd"); else System.out.println("even"); Which statement is true? A. Compilation fails. B. "odd" will always be output. C. "even" will always be output. D. "odd" will be output for odd values of x, and "even" for even values. 6) public class Switch2 final static short x = 2; public static int y = 0; public static void main(string [] args) for (int z=0; z < 3; z++) switch (z) case y: System.out.print("0 "); /* Line 11 */

case x-1: System.out.print("1 "); /* Line 12 */ case x: System.out.print("2 "); /* Line 13 */ A. 0 1 2 B. 0 1 2 1 2 2 C. Compilation fails at line 11. D. Compilation fails at line 12. 7) int x = l, y = 6; while (y--) x++; System.out.println("x = " + x +" y = " + y); A. x = 6 y = 0 B. x = 7 y = 0 C. x = 6 y = -1 D. Compilation fails. 8) public class While public void loop() int x= 0; while ( 1 ) /* Line 6 */ System.out.print("x plus one is " + (x + 1)); /* Line 8 */

Which statement is true? A. There is a syntax error on line 1. B. There are syntax errors on lines 1 and 6. C. There are syntax errors on lines 1, 6, and 8. D. There is a syntax error on line 6 9) public class Test public static void main(string [] args) int I = 1; do while ( I < 1 ) System.out.print("I is " + I); while ( I > 1 ) ; A. I is 1 B. I is 1 I is 1 C. No output is produced D. Compilation error 10) int x = 3; int y = 1; if (x = y) /* Line 3 */ System.out.println("x =" + x);

A. x=1 B. x=3 C. Compilation fails. D. The code runs with no output. 11) Here is the hierarchy of exceptions related to array index and string index errors: Exception +-- RuntimeException +-- IndexOutOfBoundsException +-- ArrayIndexOutOfBoundsException +-- StringIndexOutOfBoundsException Suppose you had a method X that could throw both array index and string index exceptions. Assuming that X does not have any try-catch statements, which of the following statements are correct? (a) The declaration for X must include throws ArrayIndexOutOfBoundsException, StringIndexOutOfBoundsException. (b) If a method calling X catches IndexOutOfBoundsException, both array and string index exceptions will be caught. (c) If the declaration for X includes throws IndexOutOfBoundsException, any calling method must use a try-catch block. (d) The declaration for X does not have to mention exceptions. 12) Which will be the first line to cause an error in the following code? Select one correct answer. 1 class Char 2 3 public static void main(string arg[]) 4 5 while(false) 6 7 System.out.println("Hello"); 8 9 while(false) 10 11 12 do; 13 while(false); 14 do 15 16 ;

17 18 while(false); 19 20 (a) Line no. 5 (b) Line no. 9 (c) Line no. 12 (d) Line no. 16 13) What will be the result of compiling and running the given program? Select one correct answer. 1 public class exception 2 3 public static void main(string args[]) 4 5 System.out.println("A"); 6 try 7 8 9 catch(java.io.ioexception t) 10 11 System.out.println("B"); 12 13 System.out.println("C"); 14 15 (a) Compile time error. (b) Program compiles correctly and prints "A" when executed. (c) Program compiles correctly and prints "A" and "C" when executed. (d) Run time error. 14. What will be the result of compiling and running the given program? Select one correct answer. 1 public class exception 2 3 public static void main(string args[]) 4 5 System.out.println("A"); 6 try

7 8 return; 9 10 catch(exception e) 11 12 System.out.println("B"); 13 14 System.out.println("C"); 15 16 (a) Compile time error in line no. 8 as main() method is declared void. (b) Program compiles correctly and prints "A" when executed. (c) Program compiles correctly and prints "A" and "C" when executed. (d) Compile time error at line no.14 due to statement not reached. 15. What will be the result of compiling and running the given program? Select one correct answer. 1 public class exception 2 3 public static void main(string args[]) 4 5 System.out.println("A"); 6 try 7 8 return; 9 10 catch(exception e) 11 12 System.out.println("B"); 13 14 finally 15 16 System.out.println("C"); 17 18 19 (a) Compile time error in line no. 8 as main() method is declared void. (b) Program compiles correctly and prints "A" when executed. (c) Program compiles correctly and prints "A" and "C" when executed. (d) Program compiles correctly and prints "A","B" and "C" when executed.

16. What will be the result of compiling and running the given program? Select one correct answer. 1 public class exception 2 3 public static void main(string args[]) 4 5 System.out.println("A"); 6 try 7 8 System.out.println("B"); 9 System.exit(0); 9 10 catch(exception e) 11 12 System.out.println("C"); 13 14 finally 15 16 System.out.println("D"); 17 18 19 (a) Program compiles correctly and prints "A" when executed. (b) Program compiles correctly and prints "A" and "B" when executed. (c) Program compiles correctly and prints "A" and "C" when executed. (d) Program compiles correctly and prints "A","B" and "C" when executed.