Question

2. (03) Consider the following Widget class declaration class Widget private int widgets; private Widget (int w) widgets = w;
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Correct option is (C).

Explanation:

Widget(int) has private access in Widget, therefore, Widget object can not be constructed.

Using private constructor we can ensure that no more than one object can be created at a time. By providing a private constructor we prevent class instances from being created in any place other than this very class.

Please give thumbsup, if you like it. Thanks.

Add a comment
Know the answer?
Add Answer to:
2. (03) Consider the following Widget class declaration class Widget private int widgets; private Widget (int...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assuming the following class declaration: class   Course {        private:               string grade_;        &n

    Assuming the following class declaration: class   Course {        private:               string grade_;               int       units_;         public:              Course ( );              Course ( string grade, int units);               ~Course ( );               string get_grade ( ) const ;               int       get_units ( ) const; }; NOTE: Class definitions are not provided but you may assume they're properly defined. Variable names used in your answers must follow our stated naming convention especially for pointer names. Write a fragment of...

  • For the following code, which statement is not true? Class Point {     private:         double...

    For the following code, which statement is not true? Class Point {     private:         double y;         double z;     public:         double x; }; a.z is available to objects of type Point declared outside the class. b.x is available to objects of type Point declared outside the class. c.x, y, and z are called members variables of the class. d.The name of the class is Point. Given the code below, What is the most accurate description of AwesomeClass(AwesomeClass...

  • It's been too long since I have done any Java programming. Can anyone help me with...

    It's been too long since I have done any Java programming. Can anyone help me with this one? Thank you 6.5 Write the declaration for a class named C that declares: (1) a private int instance variable named mX; (2) a private int class variable named mY initialized to 0; (3) a private int class constant named A which is equivalent to 100; (4) a public int class constant named B which is equivalent to 200; (5) public accessor and...

  • Here is the code for the Infant class: public class Infant{ private String name; private int...

    Here is the code for the Infant class: public class Infant{ private String name; private int age; // in months public Infant(String who, int months){ name = who; age = months; } public String getName(){ return name;} public int getAge(){ return age;} public void anotherMonth() {age = age + 1;} } The code box below includes a live Infant array variable, thoseKids. You cannot see its declaration or initialization. Your job is to find out which Infant in the array...

  • Examine the following class definition: public class Date private int year; private int month; private int...

    Examine the following class definition: public class Date private int year; private int month; private int day; public Date() { ...) public void set (int x, int y, int z) { ...) public int getYear() { ...) // returns year public int getMonth() { } // returns month public int get Day () { ...) // returns day //more methods here -- 1 Which of the following statements in a client program correctly prints out the day of the object...

  • #code for creature.cpp #include <iostream> using namespace std; class Creature { public: Creature(); void run() const;...

    #code for creature.cpp #include <iostream> using namespace std; class Creature { public: Creature(); void run() const; protected: int distance; }; Creature::Creature(): distance(10) {} void Creature::run() const { cout << "running " << distance << " meters!\n"; } class Wizard : public Creature { public: Wizard(); void hover() const; private: int distFactor; }; Wizard::Wizard() : distFactor(3) {} void Wizard::hover() const { cout << "hovering " << (distFactor * distance) << " meters!\n"; } //Created new derived class from Creature class Widget...

  • Consider this declaration of the class Fraction: class Fraction { private: int numerator, denominator; public: Fraction...

    Consider this declaration of the class Fraction: class Fraction { private: int numerator, denominator; public: Fraction operator+(const Fraction & frac2); Fraction & setNumerator(int numer); Fraction & setDenominator(int denom); }; a. Why is there only one parameter, frac2, used with operator+, even though addition has two operands? b. Write the operator: Fraction Fraction::operator+ (Fraction frac2){ } c. Write setNumerator() and setDenominator() as cascading functions: Fraction & Fraction::setNumerator(int numer) { } Fraction & Fraction::setDenominator(int denom) { } d. Assign the fractions frac1...

  • Consider the Automobile class: public class Automobile {    private String model;    private int rating;...

    Consider the Automobile class: public class Automobile {    private String model;    private int rating; // a number 1, 2, 3, 4, 5    private boolean isTruck;    public Automobile(String model, boolean isTruck) {       this.model = model;       this.rating = 0; // unrated       this.isTruck = isTruck;    }        public Automobile(String model, int rating, boolean isTruck) {       this.model = model;       this.rating = rating;       this.isTruck = isTruck;    }                public String getModel()...

  • For Questions 1-3: consider the following code: public class A { private int number; protected String...

    For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B() {    super();    System.out.println(“B() called”);...

  • For Questions 1-3: consider the following code: public class A { private int number; protected String...

    For Questions 1-3: consider the following code: public class A { private int number; protected String name; public double price; public A() { System.out.println(“A() called”); } private void foo1() { System.out.println(“A version of foo1() called”); } protected int foo2() { Sysem.out.println(“A version of foo2() called); return number; } public String foo3() { System.out.println(“A version of foo3() called”); Return “Hi”; } }//end class A public class B extends A { private char service; public B() {   super();   System.out.println(“B() called”); } public...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT