Total members 11890 |It is currently Fri Apr 19, 2024 9:23 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





What Are Constructor Methods? How to use Constructor in Java?
------------------------------------------------------------------

Constructors from a conceptual level enable the creation of an object of a given class. Constructor is a method of a class with no return parameters. Constructors also enable the initialization of any variables of a class. You can supply input parameters to constructors.

A class can have more than one constructor. It has the same name as the class itself. A default constructor doesn't have any parameters. In case of inheritance - if your subclass constructor does not explicitly call the superclass constructor, java will call the super class default constructor. If you want subclass constructor to call a specific superclass constructor, use the super keyword.

Example:

java code
Class Book
{
String title;
String publisher;
float price;
public Book()
{
}
public Book(String title)
{
this.title = title;
}
}
Class TextBook extends Book
{
public TextBook(){
}
public TextBook(String title)
{
super(title);
}




_________________
Please recommend my post if you found it helpful


Author:
Beginner
User avatar Posts: 109
Have thanks: 5 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : What Are Constructor Methods?
 Using a Constructor in jsp     -  
 Copy Constructor     -  
 Class with a Constructor in php     -  
 using of String constructor     -  
 class with constructor parameter     -  
 cannot find symbol constructor     -  
 Which methods is best for SEO?     -  
 JSP Passing Arrays to Methods     -  
 methods in ActionListener interface     -  
 Calling Overloaded Methods     -  



Topic Tags

Java OOP
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com