Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 9.5, Problem 9.5.6CP
What is wrong in the following code?
- 1. class Test {
- 2. public static void main (String[] args) {
- 3. A a= new A();
- 4. a. print();
- 5. }
- 6. }
- 7.
- 8. class A {
- 9. String s;
- 10.
- 11. A(String newS)
- 12. s = newS;
- 13. }
- 14.
- 15. public void print() {
- 16. System.out.print(s);
- 17. }
- 18. }
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Q2/ Correct the code.
class Box {
public static void main (String args []) {
int x;
int y;
}
class BoxBox {
public static void main (String args []) {
BOXBOX mybox =
new Box () ;
double H;
mybox.x = 1;
mybox.yy = 2;
H = myboxx.x + mybox.y * mybox.x;
System.ouf.println ("H
}
+ H);
}
class isinfinite_output
{
public static void main(String args[])
{
Double d = new Double(1 / 0.);
boolean x = d.isInfinite();
System.out.print(x);
}
}
What will the given code prints on the output screen.
2) class selection_statements
{
public static void main(String args[])
{
int var1
5; int
%D
var2 =
6;
if ((var2 = 1) :
System.out.print(v
ar2); else
System.out.print(++var2);
var1)
==
}
а) 1
b) 2
c) 3
d) 4
Chapter 9 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 9.3 - Prob. 9.3.1CPCh. 9.3 - How do you define a class?Ch. 9.3 - How do you declare an objects reference variable?Ch. 9.3 - How do you create an object?Ch. 9.4 - Prob. 9.4.5CPCh. 9.4 - When will a class have a default constructor?Ch. 9.5 - Which operator is used to access a data field or...Ch. 9.5 - What is an anonymous object?Ch. 9.5 - Prob. 9.5.3CPCh. 9.5 - Is an array an object or a primitive-type value?...
Ch. 9.5 - Prob. 9.5.5CPCh. 9.5 - What is wrong in the following code? 1. class Test...Ch. 9.5 - Prob. 9.5.7CPCh. 9.6 - Prob. 9.6.1CPCh. 9.6 - Prob. 9.6.2CPCh. 9.6 - Which packages contain the classes Date, Random,...Ch. 9.7 - Suppose the class F is defined in (a). Let f be an...Ch. 9.7 - Prob. 9.7.2CPCh. 9.7 - Can you invoke an instance method or reference an...Ch. 9.9 - Prob. 9.9.1CPCh. 9.9 - Prob. 9.9.2CPCh. 9.9 - In the following code, radius is private in the...Ch. 9.10 - Prob. 9.10.1CPCh. 9.10 - Show the output of the following program: public...Ch. 9.10 - Show the output of the following code:Ch. 9.10 - Prob. 9.10.4CPCh. 9.11 - What is wrong in the following code? 1public class...Ch. 9.12 - If a class contains only private data fields and...Ch. 9.12 - If all the data fields in a class are private and...Ch. 9.12 - Is the following class immutable? public class A {...Ch. 9.13 - What is the output of the following program?...Ch. 9.14 - Prob. 9.14.2CPCh. 9.14 - Prob. 9.14.3CPCh. 9 - (The Rectangle class) Following the example of the...Ch. 9 - (The Stock class) Following the example of the...Ch. 9 - (Use the Date class) Write a program that creates...Ch. 9 - Prob. 9.4PECh. 9 - (Use the GregorianCa1endar class) Java API has the...Ch. 9 - (Stopwatch) Design a class named StopWatch. The...Ch. 9 - (The Account class) Design a class named Account...Ch. 9 - (The Fan class) Design a class named Fan to...Ch. 9 - (Geometry: n-sided regular polygon) In an n-sided...Ch. 9 - Prob. 9.10PECh. 9 - (Algebra: 2 2linear equations) Design a class...Ch. 9 - (Geometry: intersecting point) Suppose two line...Ch. 9 - (The Location class) Design a class named Location...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Consider the program in Listing 5.4 . Suppose you wanted to add another species object called speciesOfTheYear,...
Java: An Introduction to Problem Solving and Programming (8th Edition)
Look at the following array definition: int set[10]; Write a statement using pointer notation that stores the v...
Starting Out with C++ from Control Structures to Objects (9th Edition)
This optional Google account security feature sends you a message with a code that you must enter, in addition ...
SURVEY OF OPERATING SYSTEMS
We can summarize the imperative programming paradigm by saying that it places emphasis on describing a process ...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
What is the purpose of an abstract class?
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
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
- PROBLEM STATEMENT: An anagram is a word that has been rearranged from another word, check tosee if the second word is a rearrangement of the first word. public class AnagramComputation{public static boolean solution(String word1, String word2){// ↓↓↓↓ your code goes here ↓↓↓↓return true;}} Can you help me with this java question the language is java please use the code I gavearrow_forwardJava - Smallest Numberarrow_forwardDon't put wrong code else downvotearrow_forward
- PROBLEM STATEMENT: Use string concatenation to append the "dogs" string to the parameter str. public class StringConcatAppend{public static String solution(String str){// ↓↓↓↓ your code goes here ↓↓↓↓return null; Can you help me with this question The language is Javaarrow_forwardFind and fix any logic and syntax errors. debug 4-1 // This program assigns values to two variables // and performs mathematical operations with them public class DebugFour1 { public static main(String args[]) { int x = 5; int y = 8; System.out.println("adding " + x + y); int z = 19; System.out.println("subtracting " + z - y); System.out.println("dividing " + z / x); System.out.println("multiplying " + x / z); } }arrow_forwardJava Input class main { publicstaticvoid main(String args[]) { boolean a =true; boolean b =false; boolean c = a ^ b; System.out.println(!c); } } Find output.arrow_forward
- PROBLEM STATEMENT: Use string concatenation to prepend the "cats" string to the parameter str. public class StringConcat{public static String solution(String str){// ↓↓↓↓ your code goes here ↓↓↓↓return null; Can you help me with this question The Language is Javaarrow_forwarddef SomeMethod(a,b): a= a+b b=b+a print(a,b,end=" ") return (a+b) def main(): x=10 y=20 print(SomeMethod(x,y)) main() x and y are called: ? a and b are called: ?arrow_forward#include void main () { int a=5,b=10,c=1; if (a && b>c) { printf("cquestionbank"); } else{ break; } }arrow_forward
- A String object in Java is considered to be mutable, i.e., the characters it contains can be changed by its methods. True Falsearrow_forwardIn Java code do the following:Write a method that accepts a String as an argument. The method should use recursion to display each individual character in the String:arrow_forwardhomework instructions- Read the steps carefully and follow them correctly. side note- please don’t use String[][] s4 as it is not used for this assignment public class SumOfDiagonals { public static void main(String[] args) { String[][] s1 = {{"2", "3", "4"}, {"5", "6", "7"}, {"8", "9", "10"}}; String[][] s2 = {{"1", "2", "3"}, {"5", "6", "7"}, {"9", "10", "11"}, {"13", "14", "15"}}; String[][] s3 = {{"1", "2", "3", "4"}, {"5", "6", "7", "8"}, {"9", "10", "11", "12"}, {"13", "14", "15", "16"}}; try { sumOfDiagonals(s1); sumOfDiagonals(s2); sumOfDiagonals(s3); } catch(NumberFormatException ex) { System.out.println("Not a valid integer"); } catch(IllegalArgumentException ex) {…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Java random numbers; Author: Bro code;https://www.youtube.com/watch?v=VMZLPl16P5c;License: Standard YouTube License, CC-BY