Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Que1. Given the following code, what is the result when run? Select the one correct answer. public class Program { public static void main(String args

Que1. Given the following code, what is the result when run? Select the one correct answer. public class Program { public static void main(String args [] ) { short eye = 1; short jay = 1; while (eye == 3 || jay < 5) { System.out.print(eye + + jay + ); eye++; jay += 2; } } }

  • A. 1 1 2 3 3 5
  • B. 1 1 2 2 3 3
  • C. No Output
  • D. An Exception is thrown
  • E. Compilation error

Que2. Given the following code, what is the result when run? Select the one correct answer. public class Program { public static void main(String args [] ) { short eye = 1; for ( ; ; ) {} } }

  • A. Program never ends - it is in an infinite loop
  • B. Compilation fails
  • C. An Exception occurs
  • D. Program terminates immediately
  • E. None of the above

Que3. Given the following code, what is the result when run? Select the one correct answer. public class Program { public static void main(String args [] ) { int k = 3; do { System.out.print ( k + ); } while ( k > 0); // this is the prefix decrement operator on variable k } }

  • A. 2 1 0
  • B. 1 2 3
  • C. 3 2 1
  • D. 0 1 2
  • E. 2 1 0 -1

Que4. Given the following code, what is the result when run? Select the one correct answer. public class Program { public static void main(String args [] ) { int x = 3, y = 5; String print = ; if (x < 5) if (y > 0) if (x < y) print += 1; else print += 2; else print += 3; else print += 4; System.out.print(print); } }

  • A. 1
  • B. 12
  • C. 13
  • D. 124
  • E. Compilation fails

Que5. Given the following code, what is the result when run? Select the one correct answer. public class Program { private static final int x = 10; public static void main (String [] args) { int x; System.out.print(x); } }

  • A. 10
  • B. 0
  • C. null
  • D. An Exception is thrown
  • E. Compilation fails

Que6.Given the following code, what is the result when run? Select the one correct answer. public class Program { public static void main(String args [] ) { short x = 2; x++; short y = 3 + x++; System.out.print(y); } }

  • A. 7
  • B. 6
  • C. 5
  • D. An Exception occurs
  • E. Compilation fails

Que7.What is the primary difference between the System.out.println and System.out.print methods? Select the one correct answer.

  • A. One prints to a printer, the other to the screen
  • B. One prints only full lines of text, the other prints partial lines of text
  • C. One includes the newline character as part the printed output, the other does not
  • D. One is for printing, the other is not for printing, it just has a similar sounding name
  • E. None of the above

Que8.What is the result of executing the following statement? Select the one correct answer. System.out.println(Hello + there + stranger);

  • A. Nothing, the statement will not compile successfully
  • B. The string "Hello"
  • C. The string "Hello there stranger"
  • D. The string "Hello there stranger" followed by a newline character

Que9.What should be done with the Scanner object used to collect command line inputs? Select the one correct answer.

  • A. It should be destroyed by calling destroy();
  • B. Nothing, it should be left alone
  • C. It should be closed by calling close();
  • D. It should be marked as invalid my calling invalidate();

Que10.What will be the value of result after this code executes? int num1 = 4, num2 = 6, num3 = 15; double num4 = 6.5, result = 0;

result = (num1 + num2 * num4) - num2 / num1 + num3 % num2;

  • A. 69
  • B. 66.5
  • C. 65.5
  • D. 45
  • E. 44.5

Que11.Given the following method

public static void updateNumber(int theNumber) { theNumber = theNumber + 6; System.out.println(theNumber); }

What is the output of the following code located in the same class?

int value = 7; System.out.println(value); updateNumber(value); System.out.println(value);

  • A.

    7 13 13

  • B.

    7 13 7

  • C.

    7 7 7

  • D.

    Runtime error because you can't change the value of theNumber in updateNumber.

Que12.Assume that you have an Account class with the following methods:

  • Account(String id, String ownerName, double balance) // standard constructor
  • void deposit(double amountToDeposit) // adds amountToDeposit to the balance
  • String toString() // returns account data in the form "id ownerName balance"

Given the following method

public static void addToAccount(Account theAcct) { theAcct.deposit(200.0); System.out.println(theAcct); }

What is the output of the following code located in the same class?

Account acct = new Account("9876","John Doe",500.0); System.out.println(acct); addToAccount(acct); System.out.println(acct);

  • A.

    9876 John Doe $500.00 9876 John Doe $700.00 9876 John Doe $700.00

  • B.

    9876 John Doe $500.00 9876 John Doe $500.00 9876 John Doe $500.00

  • C.

    Runtime error because you can't change the value of theAcct in addToAccount.

  • D.

    9876 John Doe $500.00 9876 John Doe $700.00 9876 John Doe $500.00

Que13.A programmer wants to continue a loop provided the user has typed y or Y. Which of these is correct? Assume the input is stored in a variable more of type char.

  • A.

    while ( more == y || more == Y)

  • B.

    while ( more == y && more == Y)

  • C.

    while ( more == y && more == Y)

  • D.

    while ( more == y || more == Y)

Que14.Which is the correct order that the class, package, and import statements should appear? Select the one correct answer.

  • A. class, import, package
  • B. package, class, import
  • C. import, class, package
  • D. package, import, class
  • E. import, package, class

Que15.Given the following code, what is the result when run? Select the one correct answer. public class Program { public static void main(String args [] ) { short x = 2; x++; short y = 3 + x++; System.out.print(y); } }

  • A. 7
  • B. 6
  • C. 5
  • D. An Exception occurs
  • E. Compilation fails

Que16.Which of the following classes are immutable? Select the two correct answers.

A. String

B. JPanel

C. java.util.Date

D. Double

E. java.sql.Date

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Management Systems

Authors: Patricia Ward, George A Dafoulas

1st Edition

ISBN: 1844804526, 978-1844804528

More Books

Students also viewed these Databases questions

Question

2. Outline the business case for a diverse workforce.

Answered: 1 week ago