Wednesday, 28 March 2018

Access modifier in java







package javaapplication21;





class A

{

  protected  String name="abcd"; 

private void msg1()

{

    System.out.println("hello this is msg1 and private");

}



protected void msg2()

{

    System.out.println("hello this is msg2 and protected");

}



}



class B extends A

{

public void showname()

{

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

}

}

public class JavaApplication21

{

    public static void main(String[] args)

    {

    B a=new B();

    a.msg2();

    a.showname();



     

     

       

    }

   

}


Wednesday, 21 March 2018

Super Keyword in java





package superkeyword;



class mamal

{

public String color="blue";



public void eat()

{

    System.out.println("It eats.....");

}

public void reproduces()

{

    System.out.println("It gives birth to a new living being.....");

}





}



class blueWhale extends mamal

{

 

public String Color=super.color;   

public void swim()

{

    System.out.println("It swims in sea.......");

}

   

public void allactions()

{

    super.eat();

    super.reproduces();

    swim();



}





}













public class Superkeyword {



 

    public static void main(String[] args)

   

    {

       

        blueWhale bw=new blueWhale();

        System.out.println("color is "+ bw.Color);

        bw.allactions();

   

    }

   

}


Tuesday, 20 March 2018

Method Overriding in java with practical Example





package polymorph;



class bank

{



 public double getinterest(int principle,int time)

 {



     return 0;

 }

   

   

}



class HabibMetro extends bank

{

public double getinterest(int principle,int time)

 {

     return principle* time* 0.1;

 }





}



class Alfalah extends bank

{

public double getinterest(int principle,int time)

 {

     return principle* time* 0.15;

 }





}



public class Polymorph

{



    public static void main(String[] args)

    {

     

        int p=10000,year=2;

        double interest;

      HabibMetro hb=new HabibMetro();

      interest=  hb.getinterest(p, year);

     System.out.println("Simple Interest from bank habib metro is "+interest);

 

   

     Alfalah al=new Alfalah();

   interest=  al.getinterest(p, year);

       System.out.println("Simple Interest from bank Alfalah  is "+interest);

 

     

   

   

       

    }

   

}


Wednesday, 14 March 2018

METHOD OVERLOADING IN JAVA


package javaapplication16;

class calculator
{

    public int sum(int x,int y)
    {
    return x+y;
    }

   public int sum(int x,int y,int z)
    {
    return x+y+z;
    }
 
 
   public double sum(double x,double y,double z)
    {
    return x+y+z;
    }
 

}




public class JavaApplication16
{

   
    public static void main(String[] args)
    {
        calculator c=new calculator();
        double r =c.sum(3, 4, 10);
       
        System.out.println("sum is "+r);
   
    }
   
}

Aggregation in java


package aggregate;

class Address
{

 int zipcode; 
String city,street;

public Address(int zc,String cit,String st) // parametrized constructor.........
{
this.zipcode=zc;
this.street=st;
this.city=cit;
   
}
   
   
}

class employee
{
int emp_id ;
String name;
double salary;
Address a;

public employee(int id,String name,double salary,Address ad)
{
this.emp_id=id;
this.name=name;
this.salary=salary;
this.a=ad;

}


void display()
{
    System.out.println("Emp id= "+emp_id);
    System.out.println("Emp Name= "+name);
    System.out.println("Emp Salary= "+salary);
    System.out.println("Emp Address= "+a.zipcode+" - "+a.street+" - "+a.city);
   
   
}


}





public class Aggregate {

 
    public static void main(String[] args)
    {
        Address ad=new Address(78650,"Karachi","Street-2");
        employee emp=new employee(541,"salman",76000,ad);
        emp.display();

       
    }
   
}

Monday, 12 March 2018

Hierarchical inheritance in java





package javaapplication14;



class employee

{

double salary;

}

class developer extends  employee

{

int dvbonus=5000;

String dv_name;



}



class designer extends  employee

{

int debonus=4000;

String de_name;



}







public class JavaApplication14 {



   

    public static void main(String[] args)

    {

        designer de=new designer();

       double salary= de.salary=35000;

      String name= de.de_name="ali";

       System.out.println("Name="+name+"\ntotal salary= "+(salary+de.debonus));

           

       developer d=new developer();

       salary=d.salary=50000;

       name="immad";

         System.out.println("Name="+name+"\ntotal salary= "+(salary+d.dvbonus));



    }

   

}


Types of Inheritance Single & multilevel inheritance in java





package javaapplication13;



class calculator1

{

   

public int sum(int a,int b)

{

return a+b;

}





}





class calculator2 extends calculator1

{

   

public int sub(int a,int b)

{

return a-b;

}

   

   

}





class calculator3 extends calculator2

{

   

public int mul(int a,int b)

{

return a*b;

}

}











public class JavaApplication13 {



   

    public static void main(String[] args)

    {

   int r;

    calculator2 c=new calculator3();

   r= c.sum(9, 9);

   System.out.println(r);

   r=c.sub(9,9);

   System.out.println(r);

 

   

    }

   

}



Pass Dynamically Added Html Table Records List To Controller In Asp.net MVC

Controller Code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using ...