wap To Show The Concept of Function Overridding Class Figure
wap To Show The Concept of Function Overridding Class Figure
wap To Show The Concept of Function Overridding Class Figure
class figure
{
int dim1;
int dim2;
figure(int d1,int d2)
{
dim1=d1;
dim2=d2;
}
int area()
{
System.out.println("This is basic figure class");
return(0);
}
}
class basic
{
public static void main(String args[])
{
figure f=new figure(10,10);
rec r=new rec(5,5);
tri t=new tri(6,6);
figure ref;
ref=r;
System.out.println(" Area is : "+ ref.area());
ref=t;
System.out.println(" Area is : "+ ref.area());
ref=f;
System.out.println(" Area is : "+ ref.area());
}
}
*******OUTPUT******
class per
{
float radius;
float pi=3.14F;
per(float r)
{
radius=r;
}
void area()
{
System.out.println("Radius is : "+radius);
System.out.println("Area of circle is : "+
(pi*radius*radius));
}
void par()
{
System.out.println("parameter of circle is :
"+(2*pi*radius*radius));
}
}
class formula
{
public static void main(String args[])
{
per p = new per(10.2F);
p.area();
p.par();
}
}
******OUTPUT******
class cons
{
int width;
int height;
cons()
{
width=10;
height=10;
}
cons(int h , int w)
{
height=h;
width=w;
}
cons(int h)
{
height=width=h;
}
void area()
{
int arr;
arr=height*width;
System.out.println("Area is "+arr);
}
}
class over
{
public static void main(String args[])
{
cons a=new cons();
a.area();
cons b=new cons(10,20);
b.area();
cons c=new cons(10);
c.area();
}
}
******OUTPUT******
Area is : 100
Area is : 200
Area is : 100
//wap to check wheather the num is prime or not
class prime
{
int n;
prime(int x)
{
n=x;
}
void cal()
{
int i=2;
int c=0;
while(i<=n-1)
{
if(n%i==0)
{
c++;
}
i++;
}
if(c==0)
System.out.println("No is prime ");
else
System.out.println("No is not prime ");
}
}
class prime1
{
public static void main(String args[])
{
prime obj=new prime(11);
obj.cal();
}
}
******OUTPUT******
class strpal
{
public static void main(String args[])
{
String str="madam";
String str1;
System.out.println("String is "+str);
StringBuilder obj=new StringBuilder(str);
obj.reverse();
str1=obj.toString();
if(str.compareTo(str1)==0)
System.out.println("string is palindrom");
else
System.out.println("string not palindrom");
}
}
******OUTPUT******
String is madam
String is palindrome
//wap to find the reverse of a string
class strrev
{
public static void main(String args[])
{
String str="shelja";
System.out.println("String is "+str);
StringBuilder obj=new StringBuilder(str);
obj.reverse();
System.out.println("reverse of string is "+obj);
}
}
******OUTPUT******
String is shelja
Reverse of string is ajlehs
//wap to find vowels in a given string
class strvol
{
public static void main(String args[])
{
String str="this is the string to find no of vowles";
int n=0,i,j;
j=str.length();
char arr[]=new char[40];
for(i=0;i<j;i++)
{
arr[i]=str.charAt(i);
}
for(i=0;i<j;i++)
{
if(arr[i]=='a'||arr[i]=='e'||arr[i]=='i'||arr[i]=='o'||
arr[i]=='u')
{
n++;
}
}
System.out.println("String is "+str);
System.out.println("No of vowles in string : "+n);
}
}
******OUTPUT******
String is : this is the string to find no of vowles
Vowels in the string is : 10
//wap to check wheather the given year is leap or
not
class year
{
int yr;
year(int y)
{
yr=y;
}
void cal()
{
if(yr%100==0||yr%4==0)
{
System.out.println("This is leap year");
}
else
{
System.out.println("This is nt a leap year");
}
}
}
class year1
{
public static void main(String args[])
{
year yrr=new year(1987);
yrr.cal();
}
}
******OUTPUT******
import java.awt.*;
import java.applet.*;
public class hello extends Applet
{
String str;
public void init()
{
str=getParameter("string");
if(str==null)
str="java";
str="hello"+str;
}
public void paint(Graphics g)
{
g.drawString(str,10,100);
}
}
<html>
<head>
<title>
java aplet</title>
</head>
<body>
<applet code=hello.class
width="400"
height="200" >
<param name="string" value="ss">
</applet>
</body>
</html>
******OUTPUT******
javac hello.java
java hello
“main lang”
Appletviewer applet.html
//wap to show multiplaction of matrix
class mul
{
public static void main(String args[])
{
int a[][]=new int[2][2];
int b[][]=new int[2][2];
int c[][]=new int[2][2];
int i,j,k;
a[0][0]=2;
a[0][1]=3;
a[1][0]=4;
a[1][1]=3;
b[0][0]=4;
b[0][1]=6;
b[1][0]=2;
b[1][1]=7;
******OUTPUT******
Ist matrix is
2 3
4 3
2nd matrix is
4 6
2 7
3rd matrix is
14 22
33 45