Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
7th Edition
ISBN: 9780134802213
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 6, Problem 4FTE
Find the error in the following class:
public class TwoValues
{
private int x, y;
public TwoValues()
{
x = 0;
}
public TwoValues()
{
x = 0;
y = 0;
}
}
Expert Solution & Answer
Learn your wayIncludes step-by-step video
schedule03:20
Students have asked these similar questions
26. Assume the declaration of Exercise 24.
A. Write the statements that derive
the class dummyClass from class base as a private inheritance. (2
lines are { and }.)
"A1 is {
"A2 is
"A3 is ))
B. Determine which members of class base are private, protected,
and public in class dummyClass.
"B1 is dummyClass is a de
Find the error(s) in the following class definition:
public class TestClass
private int value1;
private int value2;
public void TestClass(int num1, int num2)
{
value1= num1;
value2 = num2;
}
class A
{protected
int x1,y1,z;
public:
A(a, b,c):x1(a+2),y1(b-1),z(c+2) {
for(i=0; i<5;i++)
x1++; y1++;z++;}};
class B
{protected:
int x,y;
public:
B(a,b):x(a+1),y(b+2) {
for(i=0; i<5;i++)
x+=2; y+=1;}};
class D:public B, virtual public A
{ private:
int a,b;
public:
D(k,m,n): a(k+n), B(k,m),b(n+2),A(k,m,n) {
a=a+1;b=b+1;}});
int main()
{D ob(4,2,5);}
what the values of x1,y1 and z
Chapter 6 Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Ch. 6.1 - What does an object use its fields for?Ch. 6.1 - Prob. 6.2CPCh. 6.1 - How is a class like a blueprint?Ch. 6.1 - You have programs that create Scanner, Random, and...Ch. 6.1 - Prob. 6.5CPCh. 6.1 - What values do reference variables hold?Ch. 6.1 - Prob. 6.7CPCh. 6.2 - You hear someone make the following comment: A...Ch. 6.2 - Prob. 6.9CPCh. 6.2 - When a variable is said to reference an object,...
Ch. 6.2 - Prob. 6.11CPCh. 6.2 - Prob. 6.12CPCh. 6.2 - Prob. 6.13CPCh. 6.2 - Prob. 6.14CPCh. 6.2 - Prob. 6.15CPCh. 6.2 - What is a stale data item?Ch. 6.3 - Assume that r1 and r2 are variables that reference...Ch. 6.4 - How is a constructor named?Ch. 6.4 - What is a constructors return type?Ch. 6.4 - Prob. 6.20CPCh. 6.7 - Prob. 6.21CPCh. 6.7 - What is a methods signature?Ch. 6.7 - Look at the following class: public class...Ch. 6.7 - How many default constructors may a class have?Ch. 6.9 - Prob. 6.25CPCh. 6.9 - When designing an object-oriented application, who...Ch. 6.9 - How do you identify the potential classes in a...Ch. 6.9 - What are a classs responsibilities?Ch. 6.9 - What two questions should you ask to determine a...Ch. 6.9 - Will all of a classs actions always be directly...Ch. 6 - This is a collection of programming statements...Ch. 6 - A class is analogous to a(n) _______. a. house b....Ch. 6 - An object is a(n) ________. a. blueprint b....Ch. 6 - This is a class member that holds data. a. method...Ch. 6 - This key word causes an object to be created in...Ch. 6 - This is a method that gets a value from a classs...Ch. 6 - This is a method that stores a value in a field or...Ch. 6 - When the value of an item is dependent on other...Ch. 6 - This is a method that is automatically called when...Ch. 6 - When a local variable has the same name as a...Ch. 6 - This is automatically provided for a class if you...Ch. 6 - Prob. 12MCCh. 6 - Prob. 13MCCh. 6 - A classs responsibilities are __________. a. the...Ch. 6 - True or False: The new operator creates an...Ch. 6 - True or False: Each instance of a class has its...Ch. 6 - True or False: When you write a constructor for a...Ch. 6 - True or False: A class may not have more than one...Ch. 6 - True or False: To find the classes needed for an...Ch. 6 - Find the error in the following class: public...Ch. 6 - Prob. 2FTECh. 6 - The following statement attempts to create a...Ch. 6 - Find the error in the following class: public...Ch. 6 - Find the error in the following class: public...Ch. 6 - Design a class named Pet, which should have the...Ch. 6 - Look at the following partial class definition,...Ch. 6 - Consider the following class declaration: public...Ch. 6 - Look at the following description of a problem...Ch. 6 - The bank offers the following types of accounts to...Ch. 6 - Assume that you are writing an application that...Ch. 6 - What is the difference between a class and an...Ch. 6 - A contractor uses a blueprint to build a set of...Ch. 6 - What is an accessor method? What is a mutator...Ch. 6 - is it a good idea to make fields private? Why or...Ch. 6 - If a class has a private field, what has access to...Ch. 6 - Prob. 6SACh. 6 - Assume a program named MailList.java is stored in...Ch. 6 - Why are constructors useful for performing...Ch. 6 - Under what circumstances does Java automatically...Ch. 6 - What do you call a constructor that accepts no...Ch. 6 - Prob. 11SACh. 6 - How does method overloading improve the usefulness...Ch. 6 - Employee Class Write a class named Employee that...Ch. 6 - Car Class Write a class named Car that has the...Ch. 6 - Personal Information Class Design a class that...Ch. 6 - Retail Item Class Write a class named RetailItem...Ch. 6 - Payroll Class Design a Payroll class that has...Ch. 6 - TestScores Class Design a TestScores class that...Ch. 6 - Circle Class Write a Circle class that has the...Ch. 6 - Temperature Class Write a Temperature class that...Ch. 6 - Days in a Month Write a class named MonthDays, The...Ch. 6 - A Game of Twenty-One For this assignment, you will...Ch. 6 - Freezing and Boiling Points The following table...Ch. 6 - SavingsAccount Class Design a SavingsAccount class...Ch. 6 - Deposit and Withdrawal Files Use Notepad or...Ch. 6 - Patient Charges Write a class named Patient that...Ch. 6 - Dice Game Write a program that uses the Die class...Ch. 6 - Roulette Wheel Colors On a roulette wheel, the...Ch. 6 - Coin Toss Simulator Write a class named Coin. The...Ch. 6 - Tossing Coins for a Dollar For this assignment you...Ch. 6 - Fishing Game Simulation For this assignment, you...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Consider the following program: a. What output does the program produce? b. What output would the program produ...
Java: An Introduction to Problem Solving and Programming (8th Edition)
For each of the following activities, give a PEAS description of the task environment and characterize it in te...
Artificial Intelligence: A Modern Approach
Code an SQL statement that creates a table with all columns from the parent and child tables in your answer to ...
Database Concepts (7th Edition)
The Pitfall section entitled Leading Zeros in Number Constants suggests that you write a short program to test ...
Problem Solving with C++ (10th Edition)
Why do you think the arguments to a base class constructor are specified in the definition of the derived class...
Starting Out with C++: Early Objects
The following code transposes the elements of an M M array, where M is a constant defined by #define. When com...
Computer Systems: A Programmer's Perspective (3rd 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
- Public Class SavingsAccount { float interest; float FixedDeposit; SeniorAccount(float interest, float FixedDeposit) { this. interest = interest; this.fixedDeposit= FixedDeposit; } float calculateInterest(); { System.out.println(“Calculating Savings Account Interest”); return(FixedDeposit*interest/100); } } Public Class SeniorAccount extends SavingAccount { float seniorInterest; SeniorAccount(float interest, float FixedDeposit) { this.seniorInterest=interest; super(interest, FixedDeposit) } float calculateInterest() { System.out.println(“Calculating Savings Account Interest”); return(FixedDeposit*seniorinterest/10); } } Public static void main(String args[]) { SavingsAccount saving = new SavingsAccount(6,100000); System.out.println(saving.calculateinterest()); SeniorAccount senior=new seniorAccount(10,100000); System.out.println(Senior.calculateInterest()); } Correct the syntax and logical errorarrow_forwardPublic Class SavingsAccount { float interest; float FixedDeposit; SeniorAccount(float interest, float FixedDeposit) { this. interest = interest; this.fixedDeposit= FixedDeposit; } float calculateInterest(); { System.out.println(“Calculating Savings Account Interest”); return(FixedDeposit*interest/100); } } Public Class SeniorAccount extends SavingAccount { float seniorInterest; SeniorAccount(float interest, float FixedDeposit) { this.seniorInterest=interest; super(interest, FixedDeposit) } float calculateInterest() { System.out.println(“Calculating Savings Account Interest”); return(FixedDeposit*seniorinterest/10); } } Public static void main(String args[]) { SavingsAccount saving = new SavingsAccount(6,100000); System.out.println(saving.calculateinterest()); SeniorAccount senior=new seniorAccount(10,100000); System.out.println(Senior.calculateInterest()); } Rubric: Correct the syntax and logical errors Proper working codearrow_forwardThe following class declaration has errors. Locate as many as you can. class Box {private:double width;double length;double height; public:Box(double w, l, h){ width = w; length = l; height = h; } // Overloaded prefix ++ operator void operator++(){ ++width; ++length; } // Overloaded postfix ++ operator void operator++(){width++; length++; }... Other member functions follow ...};arrow_forward
- class Base { public: int x, y: public: Base(int i, int j) { x = i; y = j; }}; class Derived : public Base public: Derived (int i, int j) { x = i; y = j; void display() {cout « x <<" "<< y; }}; int main(void) { Derived d(5, 5); d.display(); return e; Error O X=5,Y=5 X-0,Y=0 None of the above Other:arrow_forwardclass Vehicle{String s = "This is my vehicle" ;}class Car extends Vehicle{String s = "This is my car" ;{System.out.println( super .s);}} class Truck extends Car{String s = "This is my truck" ;{System.out.println( super .s);}}public class MainClass{public static void main(String[] args){Truck t = new Truck ();System.out.println(t.s);}}arrow_forwardQUESTION 15 public class numClass { private int a; private static int y = 10; public numClass(int newX) {a=newx; } public void set(int newx) { a=newx; y+=a; } public void setY(int newy) { y=newY; } public static int getY() { return y; } }// end of class public class output { public static void main(String[] args) { numClass one = new numClass(10); numClass two = new numClass (2); try{ one. sety(30); two.set(4); if(one.getY()==30) throw new Exception ("30"); one.setY(40); } catch (Exception e) { two.sety (50); } System.out.println(two.getY()); }// end of main } // end of classarrow_forward
arrow_back_ios
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
C++ Data Members; Author: CppNuts;https://www.youtube.com/watch?v=StlsYRNnWaE;License: Standard YouTube License, CC-BY