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...
Describe the difference between verification and validation. Do both make use of test-case design methods and...
Describe the difference between verification and validation. Do both make use of test-case design methods and testing strategies?
1)What is the difference between a SYMLINK and a HARDLINK? 2) What is the difference between...
1)What is the difference between a SYMLINK and a HARDLINK? 2) What is the difference between a DAEMON and a SERVICE? 3) What is the difference between a DAEMON and a PROCESS?
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
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT