II B.Tech II Sem CSE Java Lab Exercise - 3b (Class, Objects)

b) Implementing Constructor

Aim: To write a JAVA program to implement constructor

Description:



Programs:

(i)A constructor with no parameters:

class A
{
int l,b;
A() 
{
l=10;
b=20; 
}
int area() 
{
return l*b; 
}
}
class constructordemo 
{
public static void main(String args[]) 
{
A a1=new A();
int r=a1.area(); 
System.out.println("The area is: "+r);

}

Output:


(ii)A constructor with parameters

class A 
{
int l,b;
A(int u,int v) 
{
l=u;
b=v; 
}
int area() 
{
return l*b; 
}
}
class constructordemo1 
{
public static void main(String args[]) 
{
A a1=new A(10,20); 
int r=a1.area();
System.out.println("The area is: "+r); 
}
}

Output:







No comments

File Uploading in PHP

  File Uploading in PHP PHP allow you to upload any type of a file i.e. image, binary or text files.etc..,PHP has one in built global variab...