Question

Like every general method, a constructor must also be defined in a class and can be...

Like every general method, a constructor must also be defined in a class and can be overloaded. However, in terms of functionality and syntax, it is different from a general method. How is a constructor different from a general method?

Homework Answers

Answer #1

In terms of functionality and syntax constructor is different from other general methods.

1. In terms of syntax,

(i) Constructor does not have any return type while other methods does have a return type.
(ii) Constructor name is same as the class name while other methods can have any name.
(iii) Constructor is invoked implicitly, when the object of that class is created using the new keyword while other methods needs to be called by the object of that class.

2. In terms of functionality, constructor is used to initialize the variables of the class while general methods are used to apply operations on the variables.

Hence, we can say, in terms of syntax and functionality, constructor and other general methods are totally different.

Know the answer?
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
Similar Questions
no need to explain. True or False 1. A constructor is a special Class member method....
no need to explain. True or False 1. A constructor is a special Class member method. It is automatically called when an object of the class is created. It can also be called more than once after the object is created. 2. In Java, the new operator is used to create an instance/object of a class in the heap. 3. A reference variable is a memory location contains an address of an object stored in the stack. 4. Encapsulation and...
Given a class: public class Money { int wholeNumber; int decimalPart; boolean positive; char currencySymbol; }...
Given a class: public class Money { int wholeNumber; int decimalPart; boolean positive; char currencySymbol; } Write a constructor for setting the 4 instance variables (in the order specified above). The constructor must validate the input throwing an IllegalArgumentException (you can specify any error message you see fit) if any of the following conditions are not met: either the int values are negative decimalPart is greater than 99 the currencySymbol is not one of '$', '€', or '£' Write an...
Implementing Polynomials using Singly Linked List in C++ The Term Class Create a class to represent...
Implementing Polynomials using Singly Linked List in C++ The Term Class Create a class to represent a term in an algebraic expression. As defined here, a term consists of an integer coefficient and a nonnegative integer exponent. E.g. • in the term 4X2, the coefficient is 4 and the exponent 2 • in -6X8, the coefficient is -6 and the exponent 8 Your class will have a constructor that creates a Term object with a coefficient and exponent passed as...
How do you pass two class objects as parameters? Also, if the object sq can be...
How do you pass two class objects as parameters? Also, if the object sq can be used to call getters, then what is the purpose of the move object? I would like an example with an explanation of how to do this in java since I don't understand this. Here is this example of a method with two objects as parameters. private void move(Board sq, Board move){ ... space[sq.getX()][sq.getY()]; }
Which statement is not true? Question 10 options: A subclass can add its own fields and...
Which statement is not true? Question 10 options: A subclass can add its own fields and methods. A subclass is more specific than its superclass The subclass exhibits the behaviors of its superclass and can only add upon behaviors that are defined in the superclass. Every subclass object is an object of its superclass. Interfaces are particularly used for ______. Question 8 options: polymorphysim. programming in general. assigning common functionality to possibly unrelated classes. assigning common functionality to similar classes....
can anyone please paraphrase the below passege and also add some information about smartclass and how...
can anyone please paraphrase the below passege and also add some information about smartclass and how is the relationship between smart class and special need people? for example, how smartclass can help disabled people to study well and reach their goals? Smart Class is a solution designed to help teachers in meeting with new challenges and developing students abilities and performance. It helps the teachers to access multimedia content and information ,that can be used for teaching students more effectively....
we defined, implemented, and tested a class Time. In this lab, we will continue working with...
we defined, implemented, and tested a class Time. In this lab, we will continue working with the Time class. A. Separate the class definition and class implementation from the client program. Move the class definition into a header file named Time.h and move the class implementation into a cpp file named Time.cpp. Use preprocessor directive to include header files as needed. B. Modify the Time class as follows: 1. Replace the default constructor and overloaded constructor with a constructor with...
You are asked to implement a C++ class to model a sorted array of unsigned integers....
You are asked to implement a C++ class to model a sorted array of unsigned integers. The class is to be used in an embedded application that cannot assume the presence of the STL. The array has to be dynamically allocated in such a way that allows programmers using it to specify the required size. Your class should should: (1) provide the appropriate constructors and destructor; (2) provide methods for updating, and showing numbers in/to the array (e.g., to be...
A class contains 30 students. 1) The teacher asks three questions during a class, which any...
A class contains 30 students. 1) The teacher asks three questions during a class, which any student can answer. How many unique outcomes? 2) The class is divided into 6 teams of 5 students each, numbered team #1 thru #6. Each team is to make a presentation. How many different ways can the team presentations be sequenced? 3) A team of 8 students is to be selected from the class. In how many unique ways can this team be selected?...
2n kids, all of different heights, must line up for a class picture. They will do...
2n kids, all of different heights, must line up for a class picture. They will do this in two equal rows, but for variety, they will take a picture from the front and from the right. How many ways can the kids line up so that both pictures don't have any taller kid blocking a shorter kid?
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT