You are on page 1of 7

Q-1

Code:
class Cylinder{
double r,h;
Cylinder(){
r=1;
h=1;
}
Cylinder(int a){
this.r=a;
}
Cylinder(int a,int b){
this.r=a;
this.h=b;
}
public double getArea(){
double result;
result=(2*3.14*this.r*this.r)+(3.14*this.r*this.h);
return result;
}
}

class TestCylinder{
public static void main(String[] args) {
Cylinder obj=new Cylinder();
new Cylinder(5);
new Cylinder(5,5);
System.out.println("Area:"+obj.getArea());
}
}
Output:
Q-3

Code:
class Q_3{
public static void main(String[] args) {
Q_3 obj=new Q_3();
int a=1,b=2;
obj.sum();
obj.sum(a,b);
}
void sum(){
System.out.println("This is non peramiter method");
}
void sum(int a, int b){
System.out.printf("This is peramiter method and value of a: %d and value of b:%d
.",a,b);
}
}
Output:
Q-4
Code:
class Institute{
String name,add,email;
Institute(){
name=null;
add=null;
email=null;
}
Institute(String name,String add, String email){
this.name=name;
this.add=add;
this.email=email;
}

}
class ce extends Institute
{

int n_f,n_s;

ce(){
n_f=0;
n_s=0;
}
ce(int n_f,int n_s){
this.n_f=n_f;
this.n_s=n_s;
}
void get(String n,String aa,String e,int a,int b){
name=n;
add=aa;
email=e;
n_f=a;
n_s=b;
}
void put(){

System.out.println(name+" "+add+" "+email);


System.out.println("Numbur of faculties:"+n_f);
System.out.println("Numbur of students:"+n_f);
}
}
class cse extends Institute
{

int n_f,n_s;

cse(){
n_f=0;
n_s=0;
}
cse(int n_f,int n_s){
this.n_f=n_f;
this.n_s=n_s;
}
void get(String n,String aa,String e,int a,int b){
name=n;
add=aa;
email=e;
n_f=a;
n_s=b;
}
void put(){

System.out.println(name+" "+add+" "+email);


System.out.println("Numbur of faculties:"+n_f);
System.out.println("Numbur of students:"+n_f);
}
}
class it extends Institute
{

int n_f,n_s;

it(){
n_f=0;
n_s=0;
}
it(int n_f,int n_s){
this.n_f=n_f;
this.n_s=n_s;
}
void get(String n,String aa,String e,int a,int b){
name=n;
add=aa;
email=e;
n_f=a;
n_s=b;
}
void put(){

System.out.println(name+" "+add+" "+email);


System.out.println("Numbur of faculties:"+n_f);
System.out.println("Numbur of students:"+n_f);
}
}
class Q_4{
public static void main(String[] args) {
ce obj=new ce();
it obj1=new it();
cse obj3=new cse();
obj.get("Depstar","changa","depsatr@edu.org",200,10000);
obj.put();
obj.get("Depstar","changa","depsatr@edu.org",100,1000);
obj.put();
obj.get("Depstar","changa","depsatr@edu.org",150,1000);
obj.put();
}
}
Output:

You might also like