Write A Programme For Adding Two Numbers. Initialize Both The Variables in The Programme
Write A Programme For Adding Two Numbers. Initialize Both The Variables in The Programme
Initialize both
the variables in the programme.
class add1
int a=28,b=34,c;
c=a+b;
OUTPUT
QUES 2> Write a programme for adding two numbers using command
line arguments.
class add2
int p1=Integer.parseInt(args[0]);
int p2=Integer.parseInt(args[1]);
int sum=p1+p2;
OUTPUT
QUES 3> Write a programme to calculate the factorial of a given number
using command line argument.
class fact
int n=Integer.parseInt(args[0]);
int fac=1;
for(int i=n;i>1;i--)
fac=fac*n;
n=n-1;
}}
OUTPUT
QUES 4> Write a programme to calculate the bitwise or operator , left
shift and right shift of a number.
class bit1
int a=1;
int b=2;
int c=3;
a|=4;
b>>=1;
c<<=1;
a^=c;
System.out.println("a="+a);
System.out.println("b="+b);
System.out.println("c="+c);
OUTPUT
QUES 5> Write a program to calculate the unsigned right shift -2>>>24
and -4>>>24.
class unsin
int a=-2;
int b=-4;
a>>>=24;
b>>>=24;
System.out.println("a="+a);
System.out.println("b="+b);
OUTPUT
double width;
double height;
double depth;
box()
System.out.println("default constructor");
System.out.println("parametarizd constructor");
width = w;
height = h;
depth = d;
double volume()
return width*height*depth;
class cons
b1.width=10;
b1.height=14;
b1.depth=15;
vol=b1.width*b1.height*b1.depth;
System.out.println("volume is="+vol);
vol=b2.volume();
System.out.println("volume is="+vol);
OUTPUT
{
int i,j;
A(int a,int b)
i=a;
j=b;
void show()
class B extends A
int k;
super(a,b);
k=c;
void show()
//overload show
System.out.println(msg +k);
class method
int i;
one(int i)
this.i=i;
int i;
two(int a,int b)
super(a);
i=b;
void show()
class inheritance
t.show();
}
}
OUTPUT
void areaa(double r)
double rad = r;
double arr= 3.14*r*r;
int len=l;
int brt= b;
int arr=len*brt;
void areaa(int s)
int sid=s;
int arr=s*s;
double base=b;
double hgt=h;
double arr=0.5*base*hgt;
class area
{
public static void main(String args[])
ob.areaa(0.25);
ob.areaa(4,5);
ob.areaa(10);
ob.areaa(10.0,20.0);
QUES 11> Design three classes: Student, Exam and Result. The student class has
data members such as roll no, name etc. Create a class Exam by inheriting the
Student class. The Exam class adds data members representing the marks scored
in six subjects. Derive the Result from class Exam and it has its own members such
as total marks and average. Calculate the total marks and average.
class student
r_no=r;
name=n;
coursce=c;
mrks[0]=m1;
mrks[1]=m2;
mrks[2]=m3;
mrks[3]=m4;
mrks[4]=m5;
mrks[5]=m6;
class resultstud
ob1.student1(1,"khush","bba");
ob2.exam1(10,20,30,40,50,60);
ob3.total=0;
for(int i=0;i<6;i++)
ob3.total=ob3.total+ob2.mrks[i];
ob3.avg=ob3.total/6 ;
QUES 9> WAP to increment the employee salaries on the basis of there
designation(Manager-5000, General Manager-10000, CEO-20000, worker-2000).
Use employee name, id, designation , salary as data member and inc_sal as
member function.
class e
ename=ena;
id=i;
des=de;
sal=sa;
System.out.println("employee id is "+id);
if(des=="manager")
sal=sal+5000;
sal=sal+10000;
else if(des=="CEO")
sal=sal+20000;
else if(des=="worker")
sal=sal+2000;
else
System.out.println("wrong input");
System.out.println("new salary is "+ sal);
}}
class classem
e ob = new e();
ob.e1("khush",7687,"manager",40000);
ob.inc_sal();
QUES 10> Write a class bank, containing data member: Name of Depositor, A/c
type, Type of A/c, Balance amount. Member function: To assign initial value, To
deposit an amount , to withdraw an amount after checking the balance (which
should be greater than Rs. 500) , To display name & balance.
class bank
name=n;
no=i;
type=t;
bal=b;
bal=bal+d;
if(bal>=500)
bal=bal-w;
else
System.out.println("insuffesent balance");
}
class bb
ob.deposit(10000);
ob.withdraw(500);
class mypar
System.out.println("par");
System.out.println("display");
}
}
{ super.show();
System.out.println("dispatch");
System.out.println("show1");
mypar m=d;
m.show();
m.display();
d.show1();
}
Ques . 14 wap to extends interfaces and implements interface.
interface x
void a();
void b();
interface y
{
void b();
void c();
void d();
System.out.println(" a");
System.out.println(" b");
System.out.println(" c");
System.out.println(" d");
i.a();
i.b();
i.c();
i.d();