Wednesday, September 18, 2013

java Program to Implement the Concept of Inheritance

 Program to Implement the Concept of Inheritance
class prnt
{
int a, s;
void show()
{
System.out.println("Fathre name: Mr. Roshan Lal");
}
}
class radha extends prnt
{
void get(int x,int y)
{
a = x;
s = y;
}
void show1()
{
show();
System.out.println("Std name: Radha");
System.out.println("age:" + a);
System.out.println("salary:" + s);
}
}

class single_inherit
{
public static void main(String a[])
{
radha m = new radha();
m.get(520,22000);
m.show1();
}
}

Program to Implement the Basic Functionality of a Calculator using Switch

Program to Implement the Basic Functionality of a Calculator
using Switch
import java.io.DataInputStream;
class Cal
{
public static void main(String args[])
{
DataInputStream pt=new DataInputStream(System.in);
int x,y,z,ch;
try
{
System.out.println("Enter Value of X:");
x = Integer.parseInt(pt.readLine());
System.out.println("Enter Value of Y:");
y = Integer.parseInt(pt.readLine());
System.out.println("1.Addition\n2.Subtraction
\n3.Multiplication\n4.Division");
System.out.println("Enter ur choice:");
ch = Integer.parseInt(pt.readLine());
switch(ch)
{
case 1:
z = x + y;
System.out.println("The Addition is:"+z);
break;
case 2:
z = x - y;
System.out.println("The Subtraction
is:"+z);
break;

case 3:
z = x * y;
System.out.println("The Multiplication
is:"+z);
break;
case 4:
z = x / y;
System.out.println("The Division is:"+z);
break;
default:
System.out.println("Sorry Try
Again.........");
break;
}
}
catch(Exception e)
{
System.out.println("x.getmessage()");
}
}
}

Program to Implement Overriding of Methods

 Program to Implement Overriding of Methods
class bca
{
int d;
void get(int x)
{
d = x;
}
void display()
{
System.out.println("Bca = " + d);
}
}
class mca extends bca
{
int y;
mca(int m, int y)
{
get(m);
this.y = y;
}
void display()
{
System.out.println("Bca = " + d);
System.out.println("mca y= " + y);
}
}

class override
{
public static void main(String a[])
{
mca m = new mca(100,200);
m.display();
}
}