100% found this document useful (1 vote)
8 views

Introduction to Java Programming Comprehensive Version 9th Edition Liang Test Bank download

Test bank

Uploaded by

rodeocanica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
8 views

Introduction to Java Programming Comprehensive Version 9th Edition Liang Test Bank download

Test bank

Uploaded by

rodeocanica
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Introduction to Java Programming Comprehensive

Version 9th Edition Liang Test Bank download pdf

https://testbankdeal.com/product/introduction-to-java-programming-
comprehensive-version-9th-edition-liang-test-bank/

Visit testbankdeal.com today to download the complete set of


test banks or solution manuals!
We have selected some products that you may be interested in
Click the link to download now or visit testbankdeal.com
for more options!.

Introduction to Java Programming Comprehensive Version


10th Edition Liang Test Bank

https://testbankdeal.com/product/introduction-to-java-programming-
comprehensive-version-10th-edition-liang-test-bank/

Introduction to Java Programming Comprehensive Version


10th Edition Liang Solutions Manual

https://testbankdeal.com/product/introduction-to-java-programming-
comprehensive-version-10th-edition-liang-solutions-manual/

Introduction to Java Programming Brief Version 10th


Edition Liang Test Bank

https://testbankdeal.com/product/introduction-to-java-programming-
brief-version-10th-edition-liang-test-bank/

Window on Humanity A Concise Introduction to General


Anthropology 6th Edition Kottak Test Bank

https://testbankdeal.com/product/window-on-humanity-a-concise-
introduction-to-general-anthropology-6th-edition-kottak-test-bank/
Computed Tomography Physical Principles Clinical
Applications and Quality Control 3rd Edition Seeram Test
Bank
https://testbankdeal.com/product/computed-tomography-physical-
principles-clinical-applications-and-quality-control-3rd-edition-
seeram-test-bank/

Canadian Organizational Behaviour 8th Edition McShane


Solutions Manual

https://testbankdeal.com/product/canadian-organizational-
behaviour-8th-edition-mcshane-solutions-manual/

Canadian Advertising in Action Canadian 10th Edition


Tuckwell Test Bank

https://testbankdeal.com/product/canadian-advertising-in-action-
canadian-10th-edition-tuckwell-test-bank/

Economy Today 13th Edition Schiller Solutions Manual

https://testbankdeal.com/product/economy-today-13th-edition-schiller-
solutions-manual/

Preface To Marketing Management 15Th Edition Peter Test


Bank

https://testbankdeal.com/product/preface-to-marketing-management-15th-
edition-peter-test-bank/
Accounting Information Systems 2nd Edition Richardson Test
Bank

https://testbankdeal.com/product/accounting-information-systems-2nd-
edition-richardson-test-bank/
Name:_______________________ CSCI 1302 OO Programming
Armstrong Atlantic State University
(50 minutes) Instructor: Y. Daniel Liang

Part I:

(A)
B’s constructor is invoked
A’s constructor is invoked

(B)
(a) The program has a syntax error because x does not have the compareTo
method.

(b) The program has a syntax error because the member access operator (.) is
executed before the casting operator.

(C)
(1) false
(2) true
(3) false (because they are created at different times)
(4) true

(D) Will statement3 be executed?


Answer: No.

If the exception is not caught, will statement4 be executed?


Answer: No.

If the exception is caught in the catch clause, will statement4 be


executed?
Answer: Yes.

(E) The method throws a checked exception. You have to declare to throw
the exception in the method header.

Part II:

public static Comparable max(Comparable[] a) {


Comparable result = a[0];

for (int i = 1; i < a.length; i++)


if (result.compareTo(a[i]) < 0)
result = a[i];

1
return result;
}

public class Hexagon extends GeometricObject implements Comparable {


private double side;

/** Construct a Hexagon with the specified side */


public Hexagon(double side) {
// Implement it
this.side = side;
}

/** Implement the abstract method getArea in


GeometricObject */
public double getArea() {
// Implement it ( area = 3 * 3 * side * side )
return 3 * Math.squr(3) * side * side;
}

/** Implement the abstract method getPerimeter in


GeometricObject */
public double getPerimeter() {
// Implement it
Return 6 * side;
}

/** Implement the compareTo method in


the Comparable interface to */
public int compareTo(Object obj) {
// Implement it (compare two Hexagons based on their areas)
if (this.side > ((Hexagon)obj).side)
return 1;
else if (this.side == ((Hexagon)obj).side)
return 0;
else
return -1;
}
}

Part III: Multiple Choice Questions:

1. A subclass inherits _____________ from its superclass.

a. private method
b. protected method
c. public method
d. a and c
e. b and c
Key:e

2
#
2. Show the output of running the class Test in the following code:

interface A {
void print();
}

class C {}

class B extends C implements A {


public void print() { }
}

public class Test {


public static void main(String[] args) {
B b = new B();
if (b instanceof A)
System.out.println("b is an instance of A");
if (b instanceof C)
System.out.println("b is an instance of C");
}
}

a. Nothing.
b. b is an instance of A.
c. b is an instance of C.
d. b is an instance of A followed by b is an instance of C.
Key:d

#
3. When you implement a method that is defined in a superclass, you
__________ the original method.

a. overload
b. override
c. copy
d. call
Key:b

#
4. What is the output of running the class C.

public class C {
public static void main(String[] args) {
Object[] o = {new A(), new B()};
System.out.print(o[0]);
System.out.print(o[1]);
}
}

class A extends B {
public String toString() {
return "A";
}
}

3
class B {
public String toString() {
return "B";
}
}

a. AB
b. BA
c. AA
d. BB
e. None of above
Key:a

#
5. What is the output of running class C?

class A {
public A() {
System.out.println(
"The default constructor of A is invoked");
}
}

class B extends A {
public B(String s) {
System.out.println(s);
}
}

public class C {
public static void main(String[] args) {
B b = new B("The constructor of B is invoked");
}
}
a. none
b. "The constructor of B is invoked"
c. "The default constructor of A is invoked" "The constructor of B
is invoked"
d. "The default constructor of A is invoked"
Key:c

#
6. Analyze the following code:

public class Test1 {


public Object max(Object o1, Object o2) {
if ((Comparable)o1.compareTo(o2) >= 0) {
return o1;
}
else {
return o2;
}
}
}

a. The program has a syntax error because Test1 does not have a main
method.

4
b. The program has a syntax error because o1 is an Object instance
and it does not have the compareTo method.
c. The program has a syntax error because you cannot cast an Object
instance o1 into Comparable.
d. The program would compile if ((Comparable)o1.compareTo(o2) >= 0)
is replaced by (((Comparable)o1).compareTo(o2) >= 0).
e. b and d are both correct.
Key:e

#
7. The method _____ overrides the following method:

protected double xMethod(int x) {…};

a. private double xMethod(int x) {…}


b. protected int xMethod(double x) {…}
c. public double xMethod(double x) {…}
d. public double xMethod(int x) {…}
Key:d

#
8. Which of the following possible modifications will fix the errors in
this code?

public class Test {


private double code;

public double getCode() {


return code;
}

protected abstract void setCode(double code);


}

a. Remove abstract in the setCode method declaration.


b. Change protected to public.
c. Add abstract in the class declaration.
d. b and c.
Key:c

#
9. Analyze the following code.

class Test {
public static void main(String[] args) {
Object x = new Integer(2);
System.out.println(x.toString());
}
}

a. The program has syntax errors because an Integer object is


assigned to x.
b. When x.toString() is invoked, the toString() method in the Object
class is used.
c. When x.toString() is invoked, the toString() method in the
Integer class is used.
d. None of the above.

5
Key:c

#
10. What exception type does the following program throw?
public class Test {
public static void main(String[] args) {
Object o = new Object();
String d = (String)o;
}
}

a. ArithmeticException
b. No exception
c. StringIndexOutOfBoundsException
d. ArrayIndexOutOfBoundsException
e. ClassCastException
Key:e

#
11. What exception type does the following program throw?
public class Test {
public static void main(String[] args) {
Object o = null;
System.out.println(o.toString());
}
}

a. ArrayIndexOutOfBoundsException
b. ClassCastException
c. NullPointerException
d. ArithmeticException
e. StringIndexOutOfBoundsException
Key:c

6
Random documents with unrelated
content Scribd suggests to you:
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

testbankdeal.com

You might also like