Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
Quontra Solutions
by
Java Constructors
Constructor
• Constructor in java is a special type of method that is used to
initialize the object
• Java Constructor is invoked at the time of object creation
• They do not contain any return type
• Constructor name is same as class name
Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
Types of Constructors
• Default constructor (no-arg constructor)
• Parameterized constructor
Types of constructors
Default constructor Parameterized constructor
Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
Default Constructors
Example for default constructor:
class Cons{
cons(){
System.out.println("constructor is created");
}
public static void main(String args[]){
Cons c=new Cons();
}
}
Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
Parameterized Constructors
Example for parameterized constructor
class Student4{
int id;
String name;
Student4(int i,String n){
id = i;
name = n; }
void display(){System.out.println(id+" "+name);}
public static void main(String args[]){
Student4 s1 = new Student4(111,"Karan");
Student4 s2 = new Student4(222,"Aryan");
s1.display();
s2.display(); }
}
Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
Difference between constructor and method
Constructor Method
Constructor is used to
initialize the state of an
object.
Method is used to expose
behaviour of an object.
Constructor must not have
return type
Method must have return
type.
Constructor is invoked
implicitly.
Method is invoked explicitly.
Constructor name must be
same as the class name.
Method name should not
be same as class name
Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
Constructor Overloading
• Constructors are methods that can be overloaded, just like any other
method in a class.
• Constructors having the same name with different parameter list is
called constructor overloading.
Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
Topics Covered during Training
• Classes, Objects, Keywords, Methods
• Exception Handling
• String Handling
• Multithearding
• AWT
• Swing
• Applet
• Collections
• Hibernate
• Struts etc………………
Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
Quontra Solutions Offers:
Data Warehouse
OBIEE, Cognos, Informatica
Microsoft Courses
C# .NET, ASP .NET, VB .NET
& etc….
Programming Courses
Core Java, Adv Java,
J2EE, & etc….
Testing Tools
Manual, QTP, Selenium,
Load Runner
Salesforce CRM
Salesforce CRM, ADMIN,
Developer
Networking Courses
Linux, Unix, Sun Solaris,
CCNA
Mobile Apps
Android, IOS, Cloud
Computing
Data Base
SQL PL/SQL, SQL server
DBA, ORACLE 12C DBA
Other Courses…
Business Analyst, Hadoop,
Qlikview
Contact Us
Call:(404)900-9988
Mail:info@quontrasolutions.com
Visit:www.quontrasolutions.com
Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
Follow us
Facebook: https://www.facebook.com/quontrasolutionsusa
Twitter : https://twitter.com/QuontraTraining
Google+: https://plus.google.com/+Quontrasolutions/post
Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
Java constructors

Java constructors

  • 1.
    Call : (404)900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com Quontra Solutions by Java Constructors
  • 2.
    Constructor • Constructor injava is a special type of method that is used to initialize the object • Java Constructor is invoked at the time of object creation • They do not contain any return type • Constructor name is same as class name Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
  • 3.
    Types of Constructors •Default constructor (no-arg constructor) • Parameterized constructor Types of constructors Default constructor Parameterized constructor Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
  • 4.
    Default Constructors Example fordefault constructor: class Cons{ cons(){ System.out.println("constructor is created"); } public static void main(String args[]){ Cons c=new Cons(); } } Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
  • 5.
    Parameterized Constructors Example forparameterized constructor class Student4{ int id; String name; Student4(int i,String n){ id = i; name = n; } void display(){System.out.println(id+" "+name);} public static void main(String args[]){ Student4 s1 = new Student4(111,"Karan"); Student4 s2 = new Student4(222,"Aryan"); s1.display(); s2.display(); } } Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
  • 6.
    Difference between constructorand method Constructor Method Constructor is used to initialize the state of an object. Method is used to expose behaviour of an object. Constructor must not have return type Method must have return type. Constructor is invoked implicitly. Method is invoked explicitly. Constructor name must be same as the class name. Method name should not be same as class name Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
  • 7.
    Constructor Overloading • Constructorsare methods that can be overloaded, just like any other method in a class. • Constructors having the same name with different parameter list is called constructor overloading. Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
  • 8.
    Topics Covered duringTraining • Classes, Objects, Keywords, Methods • Exception Handling • String Handling • Multithearding • AWT • Swing • Applet • Collections • Hibernate • Struts etc……………… Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
  • 9.
    Quontra Solutions Offers: DataWarehouse OBIEE, Cognos, Informatica Microsoft Courses C# .NET, ASP .NET, VB .NET & etc…. Programming Courses Core Java, Adv Java, J2EE, & etc…. Testing Tools Manual, QTP, Selenium, Load Runner Salesforce CRM Salesforce CRM, ADMIN, Developer Networking Courses Linux, Unix, Sun Solaris, CCNA Mobile Apps Android, IOS, Cloud Computing Data Base SQL PL/SQL, SQL server DBA, ORACLE 12C DBA Other Courses… Business Analyst, Hadoop, Qlikview
  • 10.
    Contact Us Call:(404)900-9988 Mail:info@quontrasolutions.com Visit:www.quontrasolutions.com Call :(404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com
  • 11.
    Follow us Facebook: https://www.facebook.com/quontrasolutionsusa Twitter: https://twitter.com/QuontraTraining Google+: https://plus.google.com/+Quontrasolutions/post Call : (404) 900-9988, (404) 990-3007, Mail Us: info@quontrasolutions.com