Question

What is the difference between methods and constructors?

What is the difference between methods and constructors?

Homework Answers

Answer #1

What is the difference between methods and constructors?


constructors:

-> It is used to build object of class
-> It binds the instance variable to objects
-> It does not return any thing
-> private constructor can be used to prohibit object creation
-> It get invoked implicitly when we create an object
-> constructor can not have return type

methods:

-> It is part of the class which provides functionality to its objects
-> It may or may not return
-> methods can be reused to another class
-> method have return type or void if no return type
-> methods can be overloaded to inherited class

Example:

class Test{
public Test(){} // default constructor
public Test(int a){} // parameterized constructor

public void print(){} // method with no return

public String toString(){return "hello";} // method with return type
}

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
what is the difference between P-value and Traditional/Critical value methods in hypothesis testing?
what is the difference between P-value and Traditional/Critical value methods in hypothesis testing?
what's the main purpose of Taguchi methods". Then, explain "what's the difference between DOE (Design of...
what's the main purpose of Taguchi methods". Then, explain "what's the difference between DOE (Design of Experiment) and Taguchi Methods" with your own ideas.
What is the difference between body composition reference methods and anthropometric field methods? Both methods capture...
What is the difference between body composition reference methods and anthropometric field methods? Both methods capture the same data Anthropometric field methods can be used as the gold standard for true body composition while reference methods are compared to that gold standard Reference methods are biologically-based, objective measures while field measures are mostly based on self-reported data collected in the field Anthropometric measures are typically more expensive than reference methods All of the following are advantages of CT and MRI...
What is the difference between an independent and a dependent t-test? What is the difference between...
What is the difference between an independent and a dependent t-test? What is the difference between a one-tailed and two-tailed test? What is the difference between a t-test and ANOVA?
. What is the difference between hedging and speculating? . What is the difference between “margin”...
. What is the difference between hedging and speculating? . What is the difference between “margin” and “maintenance margin” on a futures contract?
What is the difference between quantitative and qualitative research? Visit the Library and locate at least...
What is the difference between quantitative and qualitative research? Visit the Library and locate at least one research article that used quantitative research methods and another that used qualitative methods. Why did the researchers use the chosen method to complete their research? Was it effective?
Explain the major difference between static and nonstatic sampling. What are the three main parts of...
Explain the major difference between static and nonstatic sampling. What are the three main parts of statical and non statical methods
What is the difference between ”AND” and ”OR”? For example, is there a difference between ”rolling...
What is the difference between ”AND” and ”OR”? For example, is there a difference between ”rolling an Even AND an Odd,” and ”rolling an Even OR an odd.” Explain
What is the difference between Minority status and Culture? What is the difference between Western and...
What is the difference between Minority status and Culture? What is the difference between Western and Eastern cultures? What is the difference between a stigma vs misdiagnosing a mental illness? What are 3 norms of etiquette in across cultures? What is somatization? What are the three specific types of cultural concepts? What are the 3 ways immigrants face when arriving in the United States? What is the difference between acculturation and assimilation? What are some ways you feel like a...
primary difference between the “payoff” and the “purchase and assumption” methods of handling failed banks is...
primary difference between the “payoff” and the “purchase and assumption” methods of handling failed banks is that ____ A) The CDIC is less likely to use “payoff” method for the large bank fearing depositor losses may spur business bankruptcies B) The CDIC guarantees all deposits, not just those under $100,000 limit, when it uses the “purchase and assumption” method C) Both (A) and (B) D) Neither (A) nor (B)
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT