Constructor, Parameter & Argument.

        

        Hello, Today I am going to explain what is a 

           Parameters & Arguments

          Consider this code sample :

          void car(){
          }
          void car (int xString y){
          }
          car (2, abn345);

         When considering this code sample, you can identify that, 

             Sea green (highlight) -- is Return Type 
             Red (letters)-- are the 2 datatypes 
             Pink (highlight)-- is the PARAMETER
             Orange (letters)-- are the ARGUMENTS


  When we are calling a method the values (According to the data type) that we are giving to the parameter are called ARGUMENTS.
                  
  • We can store 2 values in a parameter
  • We can store number (int) and character (String) in a parameter as data.

        Consider this code sample : 
  
             int car (){
             }
     
        When considering this code sample, you can identify that, 
 
         Red-- is the Return Type
         Blue-- is the method name 
         Green-- is the parameter list
         Pink-- are the open\close curly brackets


       Example 1 :-     int numbers (){
                                 }
                                 numbers (A value in integer type "5");


       Example 2 :-     String letters () {
                                 }
                                 letters (Values in String type "abc1234" );


         When considering these code samples, you can identify that, the red colour letters are                 ARGUMENTS.


          Example 3 :-     int numbers (int y){
                                    return 6
                                    }
                            //output = 6  


          Example 4 :-     String numbers (String x){
                                    return "ab12"
                                    }
                                     //output = ab12
         
   
            When considering theses code samples, you can identify that, the blue colour                          letters are  ARGUMENTS.
         


          Construction

             
          Consider this code sample, 

           class A{
           public static void main(String args[]) {
             System.out.println ("java")
           }
           }
           //output = java

  • This whole class is built by a constructor          
    
         This is the process that it runs
  
          class A{
          A () {
          }
          public static void main(String args[]) {
            System.out.println ("java")
            }
          }

         Here, the orange colour part is the constructor.


  1. The 1st thing that works on a programme is a constructor.
  2. Constructor is created by the class's name without a return type.
  3. The constructor is working by the object with the name of the class.
  4. The constructor is running only when an object is created for it.

-(3rd Article)        
                                                                                                    


Thank You!
                                                                                                           


                                                                                                            
                     
                                                                                                       -Article about Java by Hirun Yapa

                  
               
                                                                                      

Comments

Popular posts from this blog

Interfaces

Super Keyword

Abstract Classes