Online Examination System for all learner!!! coming soon..

JAVA : Program to demonstrate concept of Polymorphism (Overloading).

 Demonstrate concept of Polymorphism (Overloading).

Sourse Code:

class Overloaddemo
{
   void test()
   {
               System.out.println("No Parameters");
   }
//Overload test for one integer parameter
   void test(int a)
   {
            System.out.println("a:"+a);
   }
 //Overload test for two integer parameter
 void test(int a, int b)
  {
             System.out.println("a & b:"+a +" "+b);
  }
  //overload test for double parameter
  double test(double a)
   {
              System.out.println("Double a:"+a);
                        return a*a;
   }
 }
  class Overload
   {
              public static void main(String args[])
              {
              Overloaddemo ob= new Overloaddemo();
              double result;

//call all version of test()
                        ob.test();
                        ob.test(10);
                        ob.test(10,20);
                        result=ob.test(123.25);
                        System.out.println("Result of ob.test(123.25):"+result);

              }
}

Output:

No Parameters
a=10
a & b:10 20
Double a:123.25
Result of ob.test<123.25>:15190.5625  

JAVA : Program to discuss the difference between Break and Continue.

 
Break and Continue
The keywords break and continue keywords are part of control structures in Java. Sometimes break and continue seem to do the same thing but there is a difference between them.  The break keyword is used to breaks(stopping) a loop execution, which may be a for loop, while loop, do while or for each loop. The continue keyword is used to skip the particular recursion only in a loop execution, which may be a for loop, while loop, do while or for each loop.

Code:

class breakandcontinue
//for more program please visit www.programtubenotes.blogspot.in
{
    public static void main(String args[])
    {
        // Illustrating break statement (execution stops when value of i becomes to 4.)
        System.out.println("Break Statement\n....................");

        for(int i=1;i<=5;i++)
        {
            if(i==4) break;
            System.out.println(i);
        }

        // Illustrating continue statement (execution skipped when value of i becomes to 1.)
        System.out.println("Continue Statement\n....................");

        for(int i=1;i<=5;i++)
        {
            if(i==1) continue;
            System.out.println(i);
        }
    }
}

Output:

Break Statement
....................
1
2
3
Continue Statement
....................
2
3
4
5

<<Previous Page                     Download Code                    Next Page>> 

Related JAVA Programs:

  1. Write a JAVA program to print "Hello World".
  2. Write a JAVA program to find sum of all integer greater than 100 and less than 200, that are divisible by 5.
  3. Write a JAVA program to show how method overriding helps in dynamic method dispatch.
  4. Write a JAVA program to Serach and Delete a specific element from an integer array.
  5. Write a JAVA program to illustrate how super keyword is used to call the parent class constructor within the child class.
  6. Write a JAVA program illustrating parameterized constructor.
  7. Write a JAVA program to create and access a user defined packages.
  8. Write a JAVA program to calculate the length of a string.
  9. Write a JAVA program to findout the number of Vowels present in the input string.
  10.  JAVA Program that implements the Concept of Encapsulation.


JAVA : Program that implements the Concept of Encapsulation.

 Implements the Concept of Encapsulation.

Source Code:

class Emp

{

private int empid;

private String name;

public Emp( int x,String y)

{

empid=x;

name=y;

}

public void show()

{

System.out.println("empid="+empid);

System.out.println("name="+name);

}

}

class Encap

{

public static void main(String arg[])

{

int eid=Integer.parseInt(arg[0]);

String ename=arg[1];

Emp e1=new Emp(eid,ename);

e1.show();

}

}

Output:

empid=2
name=Asish
<<Previous Page                     Download Code                    Next Page>> 

Related JAVA Programs: 

  1. Write a JAVA program to print "Hello World".
  2. Write a JAVA program to find sum of all integer greater than 100 and less than 200, that are divisible by 5.
  3. Write a JAVA program to show how method overriding helps in dynamic method dispatch.
  4. Write a JAVA program to Serach and Delete a specific element from an integer array.
  5. Write a JAVA program to illustrate how super keyword is used to call the parent class constructor within the child class.
  6. Write a JAVA program illustrating parameterized constructor.
  7. Write a Java program to discuss the difference between Break and Continue.
  8. Write a JAVA program to create and access a user defined packages.
  9. Write a JAVA program to calculate the length of a string.
  10. Write a JAVA program to findout the number of Vowels present in the input string.
  11.  JAVA Program that implements the Concept of Encapsulation.
 

C Programming Online Test 1

Following quiz provides Multiple Choice Questions (MCQs) related to C Programming Framework. You will have to read all the given answ...