Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)
11th Edition
ISBN: 9780134671604
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 13.3, Problem 13.3.4CP
What is wrong in the following code? (Note the compareTo method for the Integer and Double classes was introduced in Section 10.7.)
public class Test {
public static void main(String[] args) {
Number x = new Integer(3);
System.out.println(x.intValue());
System.out.println(x.compareTo(new Integer(4)));
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(3)
public static void test_b(int n)
{
if (n>0)
test_b(n-2);
System.out.println(n + " ");
Consider the following method:
What is printed by the call test_b(4)?
A. 0 2 4
B. 0 2
C. 2 4
D. 4 2
E. 4 20
3
(4)
What is the efficacy class of +?
n
3
A: ©(1)
B: O (log n)
C: O (n)
D: O (n log n)
E: Θ n)
java
Analyse the following code.
public class Test {
int x;
public Test(String t) {
System.out.println("Test");
}
public static void main(String[] args) {
Test test = new Test();
System.out.println(test.x);
}
}
A.
The program has a compile error because you cannot create an object from the class that defines the object.
B.
The program has a compile error because System.out.println method cannot be invoked from the constructor.
C.
The program has a compile error because x has not been initialized.
D.
The program has a compile error because Test does not have a default constructor.
Chapter 13 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)
Ch. 13.2 - Prob. 13.2.1CPCh. 13.2 - The getArea() and getPerimeter() methods may be...Ch. 13.2 - True or false? a.An abstract class can be used...Ch. 13.3 - Prob. 13.3.1CPCh. 13.3 - Prob. 13.3.2CPCh. 13.3 - Prob. 13.3.3CPCh. 13.3 - What is wrong in the following code? (Note the...Ch. 13.3 - What is wrong in the following code? public class...Ch. 13.4 - Can you create a Calendar object using the...Ch. 13.4 - Prob. 13.4.2CP
Ch. 13.4 - How do you create a Calendar object for the...Ch. 13.4 - For a Calendar object c, how do you get its year,...Ch. 13.5 - Prob. 13.5.1CPCh. 13.5 - Prob. 13.5.2CPCh. 13.5 - Prob. 13.5.3CPCh. 13.5 - Prob. 13.5.4CPCh. 13.6 - Prob. 13.6.1CPCh. 13.6 - Prob. 13.6.2CPCh. 13.6 - Can the following code be compiled? Why? Integer...Ch. 13.6 - Prob. 13.6.4CPCh. 13.6 - What is wrong in the following code? public class...Ch. 13.6 - Prob. 13.6.6CPCh. 13.6 - Listing 13.5 has an error. If you add list.add...Ch. 13.7 - Can a class invoke the super.clone() when...Ch. 13.7 - Prob. 13.7.2CPCh. 13.7 - Show the output of the following code:...Ch. 13.7 - Prob. 13.7.4CPCh. 13.7 - What is wrong in the following code? public class...Ch. 13.7 - Show the output of the following code: public...Ch. 13.8 - Prob. 13.8.1CPCh. 13.8 - Prob. 13.8.2CPCh. 13.8 - Prob. 13.8.3CPCh. 13.9 - Show the output of the following code: Rational r1...Ch. 13.9 - Prob. 13.9.2CPCh. 13.9 - Prob. 13.9.3CPCh. 13.9 - Simplify the code in lines 8285 in Listing 13.13...Ch. 13.9 - Prob. 13.9.5CPCh. 13.9 - The preceding question shows a bug in the toString...Ch. 13.10 - Describe class-design guidelines.Ch. 13 - (Triangle class) Design a new Triangle class that...Ch. 13 - (Shuffle ArrayList) Write the following method...Ch. 13 - (Sort ArrayList) Write the following method that...Ch. 13 - (Display calendars) Rewrite the PrintCalendar...Ch. 13 - (Enable GeometricObject comparable) Modify the...Ch. 13 - Prob. 13.6PECh. 13 - (The Colorable interface) Design an interface...Ch. 13 - (Revise the MyStack class) Rewrite the MyStack...Ch. 13 - Prob. 13.9PECh. 13 - Prob. 13.10PECh. 13 - (The Octagon class) Write a class named Octagon...Ch. 13 - Prob. 13.12PECh. 13 - Prob. 13.13PECh. 13 - (Demonstrate the benefits of encapsulation)...Ch. 13 - Prob. 13.15PECh. 13 - (Math: The Complex class) A complex number is a...Ch. 13 - (Use the Rational class) Write a program that...Ch. 13 - (Convert decimals to fractious) Write a program...Ch. 13 - (Algebra: solve quadratic equations) Rewrite...Ch. 13 - (Algebra: vertex form equations) The equation of a...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
The pipe assembly consists of three equal-sized pipes with flexibility stiffness EI and torsional stiffness GJ....
Mechanics of Materials (10th Edition)
Write a function called mergeLists that takes two call-by-reference arguments that are pointer variables that p...
Problem Solving with C++ (10th Edition)
Big data Big data describes datasets with huge volumes that are beyond the ability of typical database manageme...
Management Information Systems: Managing The Digital Firm (16th Edition)
This optional Google account security feature sends you a message with a code that you must enter, in addition ...
SURVEY OF OPERATING SYSTEMS
_____ are characters or symbols that perform operations on one or more operands.
Starting Out With Visual Basic (8th Edition)
Assume a telephone signal travels through a cable at two-thirds the speed of light. How long does it take the s...
Electric Circuits. (11th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Method Overloading is a feature that allows a class to have two or more methods having same name, if their argument lists are different. Argument lists could differ in: 1. Number of parameters. 2. Data type of parameters. 3. Sequence of Data type of parameters. Write different version of method sum() that display the sum of the values received as parameter according to the following main method content: public static void main(String[] args) { sum ( 10, 10 ); sum ( 10, 10, 10 ); sum ( 10.0, 10.0 ); sum ( 10, 10.0 ); sum ( 10.0, 10); } You have to define five functions with the specified types. Then, demonstrate the Argument Promotion concept by reducing the number of method to two.arrow_forwardThe following class definition has errors. Explain what is wrong and why. Rewrite a correct version of the class. class Question2( public static main(String[] args){ int num1 = 10, num2 = 20, num3; (num2 / 2)--; num3 = (num1 + num2)/num3 System.out.printin( num3 );arrow_forwardJava- Consider this method declaration: void quiz(int i) { if (i > 1) { quiz(i/2); quiz(i/2); } system.out.print(“*”); } How many asterisks are printed by the method call quiz(4) ?arrow_forward
- 3. Consider the following two classes and write down the output of the following code: public class Test extends G{ void display() { String s = m1(); System.out.println("My name is "+ s); i - 7; j = j + i; } void show(){ System.out.println(" j value is - } public static void main(String args[]) { Test t - new Test(); System.out.println("s value is = t.display(); t.i = 9; System.out.println("i value in the object="+t.i); System.out.println("j value in the object="+t.j); t.show(); } abstract class G{ String s - "Exam"; int i = 10; int j - 5; String m1(){ s = "Java"; return s; abstract void display(); abstract void show( ); } " + j); + t.s);arrow_forwardApex(Salesforce) Write the Apex Test Class for the Below Apex Method and also show the code Coverage Output Here is the Apex code: - public with sharing class MyFirstClass { public static Integer performMultiplication(Integer int1, Integer int2) { //Create a variable for checking null values Integer int3=1; //Check if both the integer not null or have some value in it if(int1!=null && int2!=null) { int3 = int1*int2; } else if (int1==null && int2!=null) { int3 = int2; } else if(int1!=null && int2==null) { int3=int1; } return int3; }}arrow_forwardJava Question - Please see attached picture. Thanks.arrow_forward
- / Java program to demonstrate how // to use gcd method of BigInteger class import java.math.BigInteger; class Test { public static int gcd(int a, int b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.intValue(); } public static long gcd(long a, long b) { BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); return gcd.longValue(); } // Driver method public static void main(String[] args) {.arrow_forwardIdentify the error(s) in the program and describe why this error occurs. Rewrite the code after correcting all errors. package Overview interface MyInt{ int a; void seta(int alpha); } public class CheckTest implements MyInt { @Override public void seta(int alpha) {a = alpha;} public static void main(String[] args) { seta(5); } }arrow_forwardQUESTION 4 Analyze the following code: public class Test { public static void main (String [] args) { int i = 0; while (i ++ < 10); System.out.println(i + 4); The program compiles despite the semicolon () on the for loop line, and displays 15. The program has a compile error because of the semicolon (;) on the while loop line. The program compiles despite the semicolon (:) on the while loop line, and displays 4.arrow_forward
- 1- class Metov{ 2- void sum(int i,int j){ 3 System.out.println(i); } 4- void sum(String c,String d){ 5 System.out.println(c+d); } 6- void sum(double x,double y){ 7 System.out.println(x+y); 8 }} - public class Run{ 11 public static void main(String[] args) 12- { 13 Metov a=new Metov(); 14 a. sum("JA","VA"); 15 a.sum(5.0,10.0); 16 10- 17 }} Answer:arrow_forwardFind the errors in the following program .6 public class WelcomeClass } (public static void main(String[] args ;int student num = 11 ;(System.out.printIn("Welcom to our java class (System.out.println("The number of students in the class is:" student_num { } (سؤال غير مجهول ) * (2 نقطة) .There is a total of 5 errors, you need to find 4 of them You can upload a file to show your answer 1 تحميل ملف أقصى حد مسموح به لعدد الملفات: 1 أقصى حد مسموح به لحجم الملف الواحد: 10MB أنواع الملفات المسموح بها: PDF, صورة إرسالarrow_forwardExamine this code and determine what happens when it is run: 1 public class Test { int x; 2 3 public Test(String t){ System.out.println("Test"); } public static void main(String[] args) { Test test = new Test ("boo"); System.out.println(test.x); } 4 5 6 7 8 10 } The program has a compile error because Test does not have a default constructor. The program has a compile error because System.out.println method cannot be invoked from the constructor. ) The program runs successfully and prints out: Test O The program has a compile error because you cannot create an object from the class that defines the object.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
6 Stages of UI Design; Author: DesignerUp;https://www.youtube.com/watch?v=_6Tl2_eM0DE;License: Standard Youtube License