Page 230 - CA_Blue( J )_Class10
P. 230

To invoke a non-static method, first create an object of the class, then call the method using that object.

                            class Example {
                                void greet() {  // Non-static method
                                    System.out.println("Hello, welcome to Java!");
                                }
                                public static void main(String[] args) {
                                    Example obj = new Example(); // Create an object of the class
                                    obj.greet(); // Call the non-static method using the object
                                }
                            }














              10.6.1 Pass by Value
              In call by value, a method is called by passing the value of parameters. In this type of method call, the copy of the actual
              parameters is sent to the formal parameters. Let us take the following example:

                             To  print the number  is  a Palindrome number or not  using  a method  boolean  palin(int).  A
                Program 1    Palindrome number is a number whose reverse is equal to the original number. For example,

                             121
                 1  class PalindromeCheck

                 2  {
                 3      boolean palin(int m)

                 4      {
                 5          int r=0, t=m;

                 6          System.out.println("Value of m before execution of loop : " + m);

                 7          while(m>0)
                 8          {
                 9              r= r*10+m%10;

                10              m=m/10;
                11          }

                12          System.out.println("Value of m after execution of loop : " + m);
                13          if(t==r)

                14              return true;
                15          else

                16              return false;
                17      }



                228228  Touchpad Computer Applications-X
   225   226   227   228   229   230   231   232   233   234   235