Total members 11895 |It is currently Sun Dec 22, 2024 3:38 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     -  
 using of String constructor     -  
 Copy Constructor     -  
 Class with a Constructor in php     -  
 class with constructor parameter     -  
 cannot find symbol constructor     -  
 Which methods is best for SEO?     -  
 Calling Overloaded Methods     -  
 Static Methods and Variables     -  
 JSP Passing Arrays to 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