Starting Out with Java: From Control Structures through Objects (6th Edition)
6th Edition
ISBN: 9780133957051
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 6, Problem 1FTE
Find the error in the following class:
public class MyClass
{
private int x;
private double y;
public void MyClass(int a, double b)
{
x = a;
y = b;
}
}
Expert Solution & Answer
Learn your wayIncludes step-by-step video
schedule03:47
Students have asked these similar questions
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
class A{
void methodA(){}
void methodB();
}
class B extends A{
void methodA(){ }
}
class A should be abstract
methodB should be abstract
both a and b
both classes are okay
Consider the following class:
public class theClass
{
private double value;
private string str;
public static int count;
public theClass ()
{
}
public theClass (double d, int, x, String s)
{
}
public void print()
{
}
public static void incrementCount()
{
}
}
a) How many members do class theClass have?
b) Compare the purpose of the two constructors.
c) Use the reference this to write the definition of a method print( )to output the value of the instance data members separated by commas.
d) Write a statement to create an object myClass of the class theClass and initialise the instance variables to 5, 10.75 and the string Class.
e) Write a definition (heading) for a copy constructor for the class.
Chapter 6 Solutions
Starting Out with Java: From Control Structures through Objects (6th Edition)
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 - 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 - 7. Circle Class
Write a circle class that has the...Ch. 6 - Prob. 8PCCh. 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 - 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
Find the error in the following pseudocode. Declare Real pi Set 3.14159265 =pi Display The value of pi is , pi
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Write a Vole program that places 0s in all the memory cells from address 0xA0 through 0xC0 but is small enough ...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Bug Collector The Bug Collector Problem A bug collector collects bugs every day for five days. Write a program ...
Starting Out with Python (4th Edition)
What is pseudocode?
Starting Out With Visual Basic (8th Edition)
Fill in the blanks in each of the following: Each parameter must specify both a(n) and a(n)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Determine the slope and deflection of end A of the cantilevered beam. E = 200 GPa and I = 65.0(106) mm4. F122
Mechanics of Materials (10th 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
- Consider the following class definition: (8) class base { public: void setXYZ(int a, int b, int c) ; voidsetX ( int a ) ; int getX ()const{returnx; } void setY ( int b ); intgetY()const{returny; } int mystryNum () {return ( x &*#x00A0;y - z &*#x00A0;z) ;} void print () const; base () } base(int a, int b, int c); protected: void setz ( int c) { z= c; } void secret(); int z= 0; private: int x= 0; int y = 0; }; a. Which member functions of the class base are protected? b. Which member functions of the class base are inline? c. Write the statements that derive the class myclass from class base as a public inheritance. d. Determine which members of class base are private, protected, and public in class myclass.arrow_forwardpublic class Father { public String name; public int age; // customer name Father(){ name=”Hassan”; age=50;} public void display(){ System.out.println(“Name:”+name); System.out.println(“Age:”+age); } } 1. Based on Figure 3, create a class named Child that inherits the Father class. Declare an instance name location (String) for class Child. 2. Define a constructor in class Child and give an appropriate initial values for the instance (name, age, location). 3. Define a method display () in class Child, execute the display ( ) method in superclass using the keyword super. Method display ( ) in class Child should print the information of name, age and location 4. Create other class named Main for the main method and create 2 objects for the 2 classes (Father and Child). Then execute the display ( ) method for Father and Child. Example of the output as in Figure 4: Father's info: Name: Josh Age: 50 Child's info: Name: Christy Age: 20 Location:…arrow_forwardConsider the following class definition: (8)class base{public:void setXYZ(int a, int b, int c);void setX(int a);int getX() const { return x; }void setY(int b);int getY() const { return y; }int mystryNum() { return (x * y - z * z); }void print() const;base() {}base(int a, int b, int c);protected:void setZ(int c) { z = c; }void secret();int z = 0;private:int x = 0;int y = 0;};a. Which member functions of the class base are protected?b. Which member functions of the class base are inline?c. Write the statements that derive the class myClass from classbase as a public inheritance.d. Determine which members of class base are private, protected,and public in class myClass.arrow_forward
- True or False, An abstract class must have at least one abstract method.arrow_forwardDetermine if this statement is true or false Take the following method, which is defined in some class: class SomeClass: SomeBaseClass{ private int override MyMethod() { //do something.... } } This is an example of run time polymorphism, as MyMethod is being redefined in the child class by the override keyword.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
- Identify the constructor for the following class class Teacher { int id; String name; } a. Teacher0 b. class) c. id() d. name()arrow_forwardpublic class Cat extends Pet { private String breed; public void setBreed(String userBreed) { breed = userBreed; } public String getBreed() { return breed; }} public class Pet { protected String name; protected int age; public void setName(String userName) { name = userName; } public String getName() { return name; } public void setAge(int userAge) { age = userAge; } public int getAge() { return age; } public void printInfo() { System.out.println("Pet Information: "); System.out.println(" Name: " + name); System.out.println(" Age: " + age); } } import java.util.Scanner; public class PetInformation { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); // create a generic Pet and a Cat Pet myPet = new Pet(); Cat myCat = new Cat(); // declare variables for pet and cat info String petName, catName, catBreed; int petAge,…arrow_forward2. Add a constructor for Animal class shown. The constructor should pass in a string parameter named "sound". 1 using System; 2 3 public class Animal 4 { 5 public string Sound { get; set; } public void Speak() { Console.Writeline("The dog says " + Sound); } 10 11 } 12 13 public class Program 14 { public static void Main() { 15 16 17 18 } 19 } A 00arrow_forward
- Find the error in each of the following code segments: // Superclasspublic class Vehicle{private double cost;(Other methods . . .)}// Subclasspublic class Car extends Vehicle{public Car(double c){cost = c;}}arrow_forward8. OOPS Theory #6 public class Car { public void horn() { System.out.println("Horn horn"); } } public class Ferrari extends Car { public void horn() { System.out.println("Ferarriiiiii"); } } public static void main(String[] args) { Ferrari ferrari = new Car(); ferrari.horn(); } Pick ONE option Horn horn Ferarriiii Cannot compile Runtime exception Clear Selection 9. OOPS Theory #7 In Java, we can achieve the abstraction by creating the blueprint of an object and only have abstract methods. What do we call this? Pick ONE option Interface Encapsulation Instance Protected Clear Selectionarrow_forwardCode: interface Bicycle{ //interface for bicycle void changeGear(int val); //abstract methods void changeSpeed(int inc); void applyBrakes(int dec); void ringBell(int count); } class NewCycle implements Bicycle{ //class for a new cycle int speed=0; //stores the speed value int gear=0; //stores the gear value @Override public void changeGear(int val) { //method to change the gear gear=val; } @Override public void changeSpeed(int inc) { //method to change the speed speed=speed+inc; } @Override public void applyBrakes(int dec) { //method to apply brakes speed=speed-dec; } @Override public void ringBell(int count) { //method to ring the bell for(int i=0;i<count;i++){ System.out.print("Clang!!"+" "); } System.out.println(""); } public void printState(){ //method to print the states System.out.println("Ring bell, Speed, Gear,…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY