What is output by the following code

Assignment Help JAVA Programming
Reference no: EM131447260

Multiple Choice Assignment.

Reading:

1- Think Java: Chapter 8, 11

2.OCA: Chapter 3, 4

Exercise on paper: (Total 8 points)

Ch. 3

1. What is output by the following code? (Choose all that apply)

1: public class Fish {

2:  public static void main(String[] args) {

3:    intnumFish = 4;

4:    String fishType = "tuna";

5:    String anotherFish = numFish + 1;

6:    System.out.println(anotherFish + " " + fishType);

7:    System.out.println(numFish + " " + 1);

8:  } }

A.   4 1

B.    41

C.    5

D.   5 tuna

E.    5tuna

F.     51tuna

G.   The code does not compile.

2.     Which of the following are output by this code? (Choose all that apply)

3: String s = "Hello";

4: String t = new String(s);

5: if ("Hello".equals(s)) System.out.println("one");

6: if (t == s) System.out.println("two");

7: if (t.equals(s)) System.out.println("three");

8: if ("Hello" == s) System.out.println("four");

9: if ("Hello" == t) System.out.println("five");

A.   one

B.    two

C.    three

D.   four

E.    five

F.     The code does not compile.

3.     Which are true statements? (Choose all that apply)

A.   An immutable object can be modified.

B.    An immutable object cannot be modified.

C.    An immutable object can be garbage collected.

D.   An immutable object cannot be garbage collected.

E.    String is immutable.

F.     StringBuffer is immutable.

G.   StringBuilder is immutable.

4.     What is the result of the following code?

7: StringBuildersb = new StringBuilder();

8: sb.append("aaa").insert(1, "bb").insert(4, "ccc");

9: System.out.println(sb);

A.   abbaaccc

B.    abbaccca

C.    bbaaaccc

D.   bbaaccca

E.    An exception is thrown.

F.     The code does not compile.

5.     What is the result of the following code?

2: String s1 = "java";

3: StringBuilder s2 = new StringBuilder("java");

4: if (s1 == s2)

5:  System.out.print("1");

6: if (s1.equals(s2))

7:  System.out.print("2");

A.   1

B.    2

C.    12

D.   No output is printed.

E.    An exception is thrown.

F.     The code does not compile.

6.     What is the result of the following code?

public class Lion {

public void roar(String roar1, StringBuilder roar2) {

    roar1.concat("!!!");

    roar2.append("!!!");

  }

public static void main(String[] args) {

  String roar1 = "roar";

StringBuilder roar2 = new StringBuilder("roar");

new Lion().roar(roar1, roar2);

System.out.println(roar1 + " " + roar2);

} }

A.   roar roar

B.    roar roar!!!

C.    roar!!! roar

D.   roar!!! roar!!!

E.    An exception is thrown.

F.     The code does not compile.

7.     Which are the results of the following code? (Choose all that apply)

String letters = "abcdef";

System.out.println(letters.length());

System.out.println(letters.charAt(3));

System.out.println(letters.charAt(6));

A.   5

B.    6

C.    c

D.   d

E.    An exception is thrown.

F.     The code does not compile.

8.     Which are the results of the following code? (Choose all that apply)

String numbers = "012345678";

System.out.println(numbers.substring(1, 3));

System.out.println(numbers.substring(7, 7));

System.out.println(numbers.substring(7));

A.   12

B.    123

C.    7

D.   78

E.    A blank line.

F.     An exception is thrown.

G.   The code does not compile.

9.     What is the result of the following code?

3: String s = "purr";

4: s.toUpperCase();

5: s.trim();

6: s.substring(1, 3);

7: s += " two";

8: System.out.println(s.length());

A.   2

B.    4

C.    8

D.   10

E.    An exception is thrown.

F.     The code does not compile.

10. What is the result of the following code? (Choose all that apply)

13: String a = "";

14: a += 2;

15: a += 'c';

16: a += false;

17: if ( a == "2cfalse") System.out.println("==");

18: if ( a.equals("2cfalse")) System.out.println("equals");

A.   Compile error on line 14.

B.    Compile error on line 15.

C.    Compile error on line 16.

D.   Compile error on another line.

E.    ==

F.     equals

G.   An exception is thrown.

11. What is the result of the following code?

4: int total = 0;

5: StringBuilder letters = new StringBuilder("abcdefg");

6: total += letters.substring(1, 2).length();

7: total += letters.substring(6, 6).length();

8: total += letters.substring(6, 5).length();

9: System.out.println(total);

A.   1

B.    2

C.    3

D.   7

E.    An exception is thrown.

F.     The code does not compile.

12. What is the result of the following code? (Choose all that apply)

StringBuilder numbers = new StringBuilder("0123456789");

numbers.delete(2,  8);

numbers.append("-").insert(2, "+");

System.out.println(numbers);

A.   01+89-

B.    012+9-

C.    012+-9

D.   0123456789

E.    An exception is thrown.

F.     The code does not compile.

13. What is the result of the following code?

StringBuilder b = "rumble";

b.append(4).deleteCharAt(3).delete(3, b.length() - 1);

System.out.println(b);

A.   rum

B.    rum4

C.    rumb4

D.   rumble4

E.    An exception is thrown.

F.     The code does not compile.

14. Which of these compile when replacing line 8? (Choose all that apply)

7: char[]c = new char[2];

8: // INSERT CODE HERE

A.   int length = c.capacity;

B.    int length = c.capacity();

C.    int length = c.length;

D.   int length = c.length();

E.    int length = c.size;

F.     int length = c.size();

G.   None of the above.

15. Which of these compile when replacing line 8? (Choose all that apply)

7: ArrayList l = new ArrayList();

8: // INSERT CODE HERE

A.   int length = l.capacity;

B.    int length = l.capacity();

C.    int length = l.length;

D.   int length = l.length();

E.    int length = l.size;

F.     int length = l.size();

G.   None of the above.

Ch. 4

1.     Which of the following can fill in the blank in this code to make it compile? (Choose all that apply)

public class Ant {

  _____ void method() { }

}

A.   default

B.    final

C.    private

D.   Public

E.    String

F.     zzz:

2.     Which of the following compile? (Choose all that apply)

A.   final static void method4() { }

B.    public final int void method() { }

C.    private void int method() { }

D.   static final void method3() { }

E.    void final method() {}

F.     void public method() { }

3.     Which of the following methods compile? (Choose all that apply)

A.   public void methodA() { return;}

B.    public void methodB() { return null;}

C.    public void methodD() {}

D.   public intmethodD() { return 9;}

E.    public intmethodE() { return 9.0;}

F.     public intmethodF() { return;}

G.   public intmethodG() { return null;}

Reference no: EM131447260

Questions Cloud

Write a statement to communicate the advantage of the groups : You're the vice president of member services at CafeMom, reporting to CEO Michael Sanchez. In addition to developing new online services, a key part of your job responsibility is crafting messages that describe the new services and persuade member..
Discuss the information technology specialization : Select a System/Software Development Life Cycle (SDLC) model and methodology then apply this model and methodology to a project using the Information Technology (IT) specialization in Banking Industry Be sure to define the SDLC model and methodol..
New job in human resources management : You've just taken a new job in human resources management and the organization's president gave you this high priority task: Give us a plan that can make performance reviews motivating to the recipients and their bosses alike.
Calculate the firms hourly revenue and total cost : Calculate the firm's hourly revenue, total cost, and profit, assuming it follows the profit-maximizing rule: Does marginal product increase or decrease as additional workers are hired?
What is output by the following code : What is output by the following code? Which are the results of the following code? Which of the following can fill in the blank in this code to make it compile?
Designing a simple website for business : Bob's Small Time Grocery has sent a request for proposal (RFP) for designing a simple website for their business. They are unsure what they want, but they do not want to pay for more than 3 pages. They also want to see samples of styling using the..
Firms balance sheet under current liabilities : Other things held constant, which of the following actions would increase the amount of cash on a company’s balance sheet? Which of the following items can be found on a firm’s balance sheet under current liabilities?
Conducting research online : From your experience and by conducting research online explain how supply chain managers can understand the complexity of their supply chain logistics. Be certain to explain at least one tool that was used to assist the supply chain manager in und..
Highlight the importance of managerial decision-making : ACC2360 - ACCOUNTING FOR MANAGERIAL ACCOUNTING TEAM ASSIGNMENT - WRITTEN REPORT. In order to highlight the importance of managerial decision-making using both financial and non-financial drivers and indicators, you need to also prepare the "Balance..

Reviews

Write a Review

JAVA Programming Questions & Answers

  Recursive factorial program

Write a class Array that encapsulates an array and provides bounds-checked access. Create a recursive factorial program that prompts the user for an integer N and writes out a series of equations representing the calculation of N!.

  Hunt the wumpus game

Reprot on Hunt the Wumpus Game has Source Code listing, screen captures and UML design here and also, may include Javadoc source here.

  Create a gui interface

Create GUI Interface in java programing with these function: Sort by last name and print all employees info, Sort by job title and print all employees info, Sort by weekly salary and print all employees info, search by job title and print that emp..

  Plot pois on a graph

Write a JAVA program that would get the locations of all the POIs from the file and plot them on a map.

  Write a university grading system in java

University grading system maintains number of tables to store, retrieve and manipulate student marks. Write a JAVA program that would simulate a number of cars.

  Wolves and sheep: design a game

This project is designed a game in java. you choose whether you'd like to write a wolf or a sheep agent. Then, you are assigned to either a "sheep" or a "wolf" team.

  Build a graphical user interface for displaying the image

Build a graphical user interface for displaying the image groups (= cluster) in JMJRST. Design and implement using a Swing interface.

  Determine the day of the week for new year''s day

This assignment contains a java project. Project evaluates the day of the week for New Year's Day.

  Write a java windowed application

Write a Java windowed application to do online quiz on general knowledge and the application also displays the quiz result.

  Input pairs of natural numbers

Java program to input pairs of natural numbers.

  Create classes implement java interface

Interface that contains a generic type. Create two classes that implement this interface.

  Java class, array, link list , generic class

These 14 questions covers java class, Array, link list , generic class.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd