• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Methods and constructors in java
 
  • 597 views

Methods and constructors in java

Methods and constructors in java

Statistics

Views

Total Views
597
Views on SlideShare
597
Embed Views
0

Actions

Likes
0
Downloads
5
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Methods and constructors in java Methods and constructors in java Presentation Transcript

    • Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
    • Methods and constructors in java Shanu k k shanukk89@gmail.com www.facebook.com/shanunn i twitter.com/shanu in.linkedin.com/in/shanu k k 9656153432
    • Typing Speed Week Target Achieved 1 25 25 2 27 30 3 35 29
    • Jobs Applied # 1 2 3 Company Designation Applied Date Current Status
    • Method oA Java method is a collection of statements that are grouped together to perform an operation o A class without method has no life,the object created by such class cannot respond to any message o Methods are declared inside the body of the class but immediately after the declaration of the instance variable
    • Method declaration Type methodname(parameter_list) { Method_body; }
    • Eg: Class rectangle { int length, width; Void getData(int x,int y) { Length=x; Width=y; } }
    • class sum { void sum(int a,int b) { System.out.println( (a+b)); } void sum(int a,int b,int c) { System.out.println( (a+b+c)); } public static void main(String args[]) { sum obj=new sum(); obj.sum(10,5); obj.sum(10,5,10);
    • Constructor: o Object we created must be given to instial values o We have done earlier using two approaches 1 2 Dot operator:access the instance variable and assign value them indiviidualy getData method:intialise each object individually
    • it would be simpler to initialise an object when it’s first created _special type of method is called construcor • Constructor have the same name as the class itself • They do not specify any return type not even void
    • • class Constructor Demo{ Constructor Demo(){ System.out.println("Inside no argument constructor"); } ConstructorDemo(String name){ System.out.println("Inside one argument constructor in Java with name: " + name); } public static void main(String args[]) { Constructor Demo d = new ConstructorDemo(); //calling no argument constructor in java Constructor Demo e = new ConstructorDemo("Testing"); //calling one argument constructor in java } }
    • • Output: Inside no argument constructor Inside one argument constructor in Java with name: Testing •
    • If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
    • Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550