|
INTERVIEW QUESTIONS
J2EE
CORE JAVA
DETAILS
Question: What are the differences between Contructors and Methods?
Answer: Constructors Methods
Purpose
Create an instance of a class
Group Java statements
Modifiers
Cannot be abstract, final, native, static, or synchronized
Can be abstract, final, native, static, or synchronized
Return Type
No return type, not even void
void or a valid return type
Name
Same name as the class (first letter is capitalized by convention) -- usually a noun
Any name except the class. Method names begin with a lowercase letter by convention -- usually the name of an action
this
Refers to another constructor in the same class. If used, it must be the first line of the constructor
Refers to an instance of the owning class. Cannot be used by static methods.
super Calls the constructor of the parent class. If used, must be the first line of the constructor Calls an overridden method in the parent class
Inheritance Constructors are not inherited Methods are inherited
|
|
|
Category |
Core Java Interview Questions & Answers -
Exam Mode /
Learning Mode
|
Rating |
(0.3) By 6720 users |
Added on |
9/23/2014 |
Views |
69886 |
Rate it! |
|
|
Question:
What are the differences between Contructors and Methods?
Answer:
Constructors Methods
Purpose
Create an instance of a class
Group Java statements
Modifiers
Cannot be abstract, final, native, static, or synchronized
Can be abstract, final, native, static, or synchronized
Return Type
No return type, not even void
void or a valid return type
Name
Same name as the class (first letter is capitalized by convention) -- usually a noun
Any name except the class. Method names begin with a lowercase letter by convention -- usually the name of an action
this
Refers to another constructor in the same class. If used, it must be the first line of the constructor
Refers to an instance of the owning class. Cannot be used by static methods.
super Calls the constructor of the parent class. If used, must be the first line of the constructor Calls an overridden method in the parent class
Inheritance Constructors are not inherited Methods are inherited Source: CoolInterview.com
Constructors are invoked using the new keyword. Methods can be invoked by using the dot operator on the object of the class. Source: CoolInterview.com
Answered by: Ramya | Date: 5/5/2010
| Contact Ramya
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|
|
Related Questions |
View Answer |
|
Can constructor be inherited?
|
View Answer
|
|
How does the Java default constructor be provided?
|
View Answer
|
|
What is Constructor?
|
View Answer
|
|
Can there be an abstract class with no abstract methods in it?
|
View Answer
|
|
When you declare a method as abstract, can other nonabstract methods access it?
|
View Answer
|
|
When should I use abstract classes and when should I use interfaces?
|
View Answer
|
|
What are the differences between Interface and Abstract class?
|
View Answer
|
|
Can we instantiate an abstract class?
|
View Answer
|
|
What is an abstract class?
|
View Answer
|
|
What is a marker interface?
|
View Answer
|
|
What modifiers are allowed for methods in an Interface?
|
View Answer
|
|
Do interfaces have member variables?
|
View Answer
|
|
Can we create an object for an interface?
|
View Answer
|
|
Can we instantiate an interface?
|
View Answer
|
|
What is an Interface?
|
View Answer
|
|
How do you prevent a method from being overridden?
|
View Answer
|
|
What is super?
|
View Answer
|
|
How to invoke a superclass version of an Overridden method?
|
View Answer
|
|
Is it possible to override the main method?
|
View Answer
|
|
Can overloaded methods be override too?
|
View Answer
|
Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.
View All Core Java Interview Questions & Answers - Exam Mode /
Learning Mode
|