svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · web...

47
Progr@m~ 51 Aim: Write a program to create class with same name and different signature. Class Sample { void add(int a,int b) { System.out.println("sum of two="+(a+b)); } void add(int a,int b,int c) { System.out.println("sum of three="+(a+b+c)); } } class OverLoad { public static void main(String arg[]) { Sample s = new Sample(); s.add(20,25); s.add(20,25,30); } } Output:

Upload: phunganh

Post on 30-Mar-2018

223 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Progr@m~ 51Aim: Write a program to create class with same name and different signature. Class Sample{

void add(int a,int b){

System.out.println("sum of two="+(a+b));}void add(int a,int b,int c){

System.out.println("sum of three="+(a+b+c));}

}class OverLoad{

public static void main(String arg[]){

Sample s = new Sample();s.add(20,25);s.add(20,25,30);

}}Output:

Page 2: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Progr@m ~52Aim: Write a program that contain Super and Subclass with same name and Same signature.class Animal{

void move(){

System.out.println("Animals can move");}

}class Dog extends Animal{

void move(){

System.out.println("Dogs can walk and run");}

}public class OverRide{

public static void main(String arg[]){

Animal a = new Animal();Animal b = new Dog();a.move();b.move();

}}

Output:

Progr@m ~53

Page 3: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Aim: Write a program to show the use of static polymorphism. class Animal{

static void move(){

System.out.println("Animals can move");}

}class Dog extends Animal{

static void move(){

System.out.println("Dogs can walk and run");}

}public class StaticPoly{

public static void main(String arg[]){

Animal.move();Dog.move();

}}

Output:

Progr@m~ 54

Page 4: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Aim: Write a program for abstract class using abstract method & class.

abstract class saurabh{

abstract void abstractmethod();

void nonabstract(){

System.out.println("this is concret method");}

}

class Child extends vipal{

void abstractmethod(){

System.out.println("B is must be impliment of abstract method");}

} class AbstactDemo1{

public static void main(String a[]){

Child b=new Child();b.abstractmethod();b.nonabstract();

}}Output:

Progr@m~ 55

Page 5: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Aim: Write a program to create person class which contain general details of person and create a sub class employ which contain company details of a person. Reuse the general details of the person class using inheritance.

class Person{

String name;String PerametarAdress;int age;void setpermentDetail(String name,String PerametarAdress,int age){

this.name=name;this.PerametarAdress=PerametarAdress;this.age=age;

}

void getPermentDetail(){

System.out.println("name="+name);System.out.println("PerametarAdress="+PerametarAdress);System.out.println("age="+age);

}}class Employ extends Person{

int id;String compnyname;String companiadress;Employ(int id,String compnyname,String companiadress,String name,String PerametarAdress,int age ){

this.id=id;this.companiadress=companiadress;this.compnyname=compnyname;

}

void getEmployDetail(){

System.out.println("id adress"+id);System.out.println("companiname="+compnyname);System.out.println("companiadress="+companiadress);

}}

class InheriDemo1{

public static void main(String a[]){

Employ e1=new Employ(202,"softwer","amdavad","saurabh","ghandhinagar",20);e1.getEmployDetail();

Page 6: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

}}

Output:

Progr@m~ 56Aim:Write a program to illustrate order calling of default constructor to Super & Sub class.class One{

One(){

System.out.println("super class defolt call");}

}class Two extends One{

Two(){System.out.println("sub class defolt consructor calld");}

}class Const{

public static void main(String a[]){

Two t=new Two();}

}

Output:

Progr@m ~57

Page 7: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Aim: Write a program to using Super keyword to access superclass, variable, class A{

int x;A(int x){

this.x=x;}void show(){

System.out.println("super class method;x="+x);}

}class B extends A{

int y;B(int a,int b){

super(a);y=b;

}void show(){

super.show();System.out.println("y="+y);System.out.println("super x="+super.x);

}}class SuperUse{

public static void main(String a[]){

B ob=new B(10,20);ob.show();

}}

Output:

Progr@m ~58

Page 8: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Aim: Write a program to convert the one class father in to mother in using superclass sub class. interface Father{

double Property=1000;double Hight=5.6;

}interface Mother{

double Property=30000;double Hight=5.4;

}class Myclass implements Father,Mother{

void show(){

System.out.println ("total proparty="+(Father.Property+Mother.Property));System.out.println ("total Hight="+(Father.Hight+Mother.Hight));

}}class InetrFaceDemo{

public static void main(String a[]){

Myclass ob=new Myclass();ob.show();

}}Output:

PRACTIC@L~59

Page 9: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

AIM: Write a java application which show use of instance of operator.

public class P59{

public static void main( String arg[]){

P59 DemoObj=new P59();if (DemoObj instanceof P59){

System.out.println(" DemoObj is a

instance of demo class");}else{

System.out.println(" DemoObj is not

a instance of demo class");}

}}

OUTPUT:

PRACTIC@L~60AIM: Write a java application which show use of interface

interface Shape{

void area();void volume();double pi=3.14;

}class Circle implements Shape{

double r;Circle(double radius){

r=radius;}public void area(){

Page 10: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

System.out.println("Area os a circle is :"+pi*r*r);}public void volume()

{System.out.println("Volume of a rectangle is :"+2*pi*r);

}}class Rectangle implements Shape{

double l,b;Rectangle(double length,double breadth){

l=length;b=breadth;

}public void area(){

System.out.println("Area of a reactangle is " +l*b);}public void volume(){

System.out.println("Volume of a rectangle :"+2*(l+b));}

}class P60{

public static void main(String arr[]){

Circle ob1=new Circle(10.2);ob1.area();ob1.volume();Rectangle ob2=new Rectangle(12.6,23.55);ob2.area();ob2.volume();

}}

Output:

PRACTIC@L-61

Page 11: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

AIM: Write a java application related to interface.

interface Calculator {

int add(int a,int b);int subtract(int a,int b);int multiply(int a,int b);int divide(int a,int b);

}class P61 implements Calculator{

public int add(int a,int b){

return a+b;}

public int subtract(int a,int b){

return a-b;}public int multiply(int a,int b){

return a*b;}public int divide(int a,int b){

return a/b;}

public static void main(String args[]){

P61 c=new P61();System.out.println("Value after addition = "+c.add(5,2));System.out.println("Value after Subtraction = "+c.subtract(5,2));System.out.println("Value after Multiplication = "+c.multiply(5,2));System.out.println("Value after division = "+c.divide(5,2));

}}

Output:

Page 12: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

PRACTIC@L-62AIM: Write a java application to illustrate how to achieve multiple inheritance using interfaces.

interface Father{

double PROPERTY=10000;double HEIGHT=5.6;

}interface Mother{

double PROPERTY=30000;double HEIGHT=5.4;

}class Myclass implements Father,Mother{

void show(){

System.out.println("Total Propert is:"+(Father.PROPERTY+Mother.PROPERTY));System.out.println("Average height is:"+(Father.HEIGHT + Mother.HEIGHT)/2);

}}class P62{

public static void main(String arr[]){

Myclass obj1= new Myclass();obj1.show();

}}

OUTPUT:

Page 13: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

PRACTIC@L-64AIM: Write a program to show how to creat a subpackeg in a packeg

Package Pack1.Pack2;public class Sample{

public void show(){

System.out.println("Hello.java saurabh kadia");}

}

Output:

Progr@m~ 63.1AIM:write a program to genret packet in to pack and insurch addition and subsretion in class file in to pacage

package pack;public class Adiition

{private double d1,d2;public Adiition(double a,double b){d1=a;d2=b;}public void sum(){System.out.println("addition is="+(d1+d2));}}Output:

Page 14: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

import pack.Adiition;class Use{public static void main(String a[]){Adiition c1=new Adiition(10,20);c1.sum();}}Output:

package pack;public class Subtetion

{private double d1,d2;public Subtetion(double a,double b){d1=a;d2=b;}public void sub(){System.out.println("substretion is="+(d1-d2));}}

Output:

Program 63 -2import pack.Subtetion;import pack.Adiition;

Page 15: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

class Use{public static void main(String a[]){Adiition c1=new Adiition(10,20);c1.sum();Subtetion c2=new Subtetion(10,20);c2.sub();}}

Progr@m~65AIM:Write a program to the using of Stream file input string class

import java.io.*;class FileInput{

public static void main(String args[])throws Exception{

int i;int n;int m;InputStream obj=new

FileInputStream("D:\baurabh.txt");System.out.println("total avlbal

byte="+(n=obj.available()));

m=n-400;

System.out.println(m);for(i=0;i<m;i++)

System.out.println("\n Skiping some tex");obj.skip(n/2);

System.out.println("\n skip

avlabal="+obj.available());

Page 16: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

obj.close();}

}

Out put:

Progr@m~66AIM:Write a progtam to show the file output string class

import java.io.*;

class FileOutput{

public static void main(String a[])throws Exception{

String s="saurabh kadia \n"+"and so nice man";byte b[]=s.getBytes();OutputStream obj=new FileOutputStream("baurabh.txt");for(int i=0;i<b.length;i++)obj.write(b[i]);System.out.println("\n the data is write");obj.close();

}

}

Page 17: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Output:

Progr@m~ 67;AIM:write a program to show the datainput class and dataoutput class in the sring class

import java.io.*;class DataSteram{

public static void main(String a[])throws Exception{

DataOutputStream obj=new DataOutputStream(new FileOutputStream("baurabh.txt"));

obj.writeUTF("saurabh");obj.writeDouble(55.5);obj.writeUTF("subham");obj.writeInt(52);obj.writeUTF("saurav");obj.writeChar('a');obj.close();

DataInputStream in=new DataInputStream(new FileInputStream("baurabh.txt"));System.out.println(in.readUTF()+":"+in.readDouble());System.out.println(in.readUTF()+":"+in.readInt());System.out.println(in.readUTF()+":"+in.readChar());

}}

Output:

Page 18: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Progr@m ~68AIM:write a program the show buffaredinput class and buffaredoutput class in the string function

import java.io.*;class BufferedDemo{

public static void main(String a[])throws Exception{

DataOutputStream obj=new DataOutputStream(new BufferedOutputStream(new FileOutputStream("baurabh.txt")));

obj.writeUTF("saurabh");obj.writeDouble(55.5);obj.writeUTF("subham");obj.writeInt(52);obj.writeUTF("saurav");obj.writeChar('a');obj.close();

DataInputStream in=new DataInputStream(new BufferedInputStream(new FileInputStream("baurabh.txt")));

System.out.println(in.readUTF()+":"+in.readDouble());System.out.println(in.readUTF()+":"+in.readInt());System.out.println(in.readUTF()+":"+in.readChar());

}}

Page 19: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Output:

Progr@m~ 69:AIM:Writea program to genret the releted to random accesh file class

import java.io.*;

class RandomAcces{

public static void main(String[] a)throws IOException{

RandomAccessFile in=new RandomAccessFile("Rendom_Input.txt","rw");

in.setLength(0);for(int i=0;i<10;i++)

in.writeInt(i);in.seek(0);System.out.println("contors of the file");for(int i=0;i<10;i++)System.out.print("\n aa="+in.readInt());System.out.println("\n length of file row="+in.length());

in.seek(0);System.out.println("\n a="+in.readInt());in.seek(3*4);System.out.println("\n read four no="+in.readInt());

in.seek(6*4);in.writeInt(100);

Page 20: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

System.out.println("\n modifictoin of sevanth row=");in.seek(in.length());

in.writeInt(500);System.out.println("\t aplet the no");in.seek(0);System.out.println("\n view of file");for(int i=0;i<10;i++)System.out.println("\n ans= "+in.readInt());in.close();

}}Output:

Page 21: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

PROGR@M~ 70AMI:write a program to show objectinput and objectoutput class

import java.io.*;class ObjectDemo

{public static void main(String a[])throws ClassNotFoundException,IOException{

ObjectOutputStream o=new ObjectOutputStream (new FileOutputStream("baurabh.txt"));

o.writeObject(new java.util.Date());o.close();ObjectInputStream d=new ObjectInputStream(new

FileInputStream("baurabh.txt"));java.util.Date date=(java.util.Date)(d.readObject());System.out.println("\n the data is="+date);d.close();

}}

Output:

Page 22: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Progr@m ~71AIM:write a program to creat throw using thread class

class MyThread extends Thread{

public void run(){

System.out.println("this tread is running...");}

}class ThreadDemo{

public static void main(String a[]){

MyThread t=new MyThread();t.start();

}}

Out put

Page 23: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Progr@m ~71AIM:write a program to creat throw using thread class

class A extends Thread{

public void run(){

for(int i=1;i<=5;i++){

System.out.println("\t From ThreadA: i= "+i);}System.out.println("Exit from A");

}}class B extends Thread{

public void run(){

for(int j=1;j<=5;j++){

System.out.println("\t From ThreadB: j= "+j);}System.out.println("Exit from B");

}}class C extends Thread{

public void run(){

for(int k=1;k<=5;k++){

System.out.println("\t From ThreadC: k= "+k);}System.out.println("Exit from C");

}}class ThreadTest{

public static void main(String args[]){

A dt1=new A();dt1.start();B dt2=new B();dt2.start();C dt3=new C();dt3.start();

Page 24: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

}}

Output:

Page 25: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Progr@m ~72AIM:write a program creat throws using runebal interface

class A implements Runnable{

public void run(){

for(int i=1;i<=5;i++){

System.out.println("\t From ThreadA: i= "+i);}System.out.println("Exit from A");

}}class B implements Runnable{

public void run(){

for(int j=1;j<=5;j++){

System.out.println("\t From ThreadB: j= "+j);}System.out.println("Exit from B");

}}class C implements Runnable{

public void run(){

for(int k=1;k<=5;k++){

System.out.println("\t From ThreadC: k= "+k);}System.out.println("Exit from C");

}}class ThreadTest1{

public static void main(String args[]){

A dt1=new A();Thread t1=new Thread(dt1);t1.start();B dt2=new B();Thread t2=new Thread(dt2);t2.start();C dt3=new C();Thread t3=new Thread(dt3);

Page 26: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

t3.start(); }

}

Output:

Page 27: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Progr@m ~73AIM:write a program to genret to threads priority

class A extends Thread{

public void run(){

System.out.println("Thread A started");for(int i=1;i<=4;i++){

System.out.println("\t From ThreadA: i= "+i);}System.out.println("Exit from A");

}}class B extends Thread{

public void run(){

System.out.println("Thread B started");for(int j=1;j<=4;j++){

System.out.println("\t From ThreadB: j= "+j);}System.out.println("Exit from B");

}}

class C extends Thread{

public void run(){

System.out.println("Thread C started");for(int k=1;k<=4;k++){

System.out.println("\t From ThreadC: k= "+k);}System.out.println("Exit from C");

}}class ThreadPriority{

public static void main(String args[]){

A threadA=new A();B threadB=new B();C threadC=new C();threadC.setPriority(Thread.MAX_PRIORITY);

Page 28: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

threadB.setPriority(threadA.getPriority()+1);threadA.setPriority(Thread.MIN_PRIORITY);threadA.start();threadB.start();threadC.start();

}}

Output:

Page 29: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Progr@m ~74AIM:write a program to thread togenret the syncronization

class MyThread implements Runnable {

String account;public MyThread(String s) {

account = s;}public void run(){

account.deposit();}

} class YourThread implements Runnable {

String account;public YourThread (String s) {

account = s;}public void run() {

account.withdraw(); }

} class HerThread implements Runnable {

String account;public HerThread (String s) {

account = s; }public void run() {

account.enquire(); }

} class InternetBankingSystem1 {

public static void main(String [] args ) {

MyThread accountObject=new MyThread(); Thread t1 = new Thread(new MyThread(accountObject));

Page 30: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Thread t2 = new Thread(new YourThread(accountObject));Thread t3 = new Thread(new HerThread(accountObject));t1.start();t2.start();t3.start();

} }class Account {

int balance;int deposit_amount;

public synchronized void deposit( ) {

balance += deposit_amount;}

public synchronized void withdraw( ) {

balance -= deposit_amount;}

public synchronized void enquire( ) { // display balance;

}

}Output:

Page 31: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Progr@m ~75AIM:write a program to genret using exception try and catch blockclass Exception{

public static void main(String args[]){

int a=10;int b=0,c;try{

c=a/b;}catch(ArithmeticException e){

System.out.println("divide by zero");}

}}Output

Page 32: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Progr@m~76 AIM:write a program to the multy catch block to genret programpublic class MultiCatch{

public static void main(String a[]){

int array[]={20,30,40};int num1=15, num2=0;int res=0;try{

res=num1/num2;System.out.println("throws is ans:"+res);for(int s=2;s>=0;s++){

System.out.println("the value of array :"+array[s]);}

}catch(ArrayIndexOutOfBoundsException e){

System.out.println("error is bound");}catch(ArithmeticException e)

Page 33: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

{System.out.println("can de divaid by zero");

}}

}

Output:

Progr@m~ 77AIM:write a program to gentret the handling unreadabal code problam

public class Hndaling{

public static void main(String args[]){

String atr="Excetion";int len=0;try{

StringBuffer a=new StringBuffer(atr);len=atr.length();for(int c=len;c>=0;c--){

System.out.println(a.charAt(c));}

}catch(Exception e)

{System.out.println(e);

Page 34: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

}}

}Output:

Progr@m~78AIM:write a program to genret the releted to Excception handling using “Throw” keyword

class ThrowD{

static void demoproc(){

try{

throw new NullPointerException("demo");

}catch(NullPointerException e)

{System.out.println("Caught inside demo:");throw e;

}}public static void main(String a[]){

try{

demoproc();

Page 35: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

}catch(NullPointerException e){

System.out.println("recaught:"+e);}

}}

Output:

Progr@m~79AIM:write a program to genret the releted to Excception handling using “Throws” keyword

class ThrowsDe{

static void throwone()throws IllegalAccessException{

System.out.println("inside throwes");

throw new IllegalAccessException("demo");}public static void main(String a[]){

try{

throwone();}catch(IllegalAccessException e){

System.out.println("cauthy"+e);}

}}

Page 36: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Output:

Progr@m~80AIM:write a program to genret the releted to Excception handling using “Finally” keyword

public class Exce{

public static void main(String a[]){

int s[]=new int[2];try{

System.out.println("acces element trows :"+s[3]);}catch(ArrayIndexOutOfBoundsException e){

System.out.println("Exception trows:"+e);}finally{

s[0]=6;System.out.println("first element value is:"+s[0]);System.out.println("the finaly element is:");

}}

}

Page 37: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

Output:

Progr@m ~81AIM :Write a program to genret creat the diagram

import java.applet.*;

import java.awt.*;/*<applet code="Hello" width="500" height="500"></applet>*/

public class Hello extends Applet{

public void init(){

setBackground(Color.black);}

public void paint (Graphics g) { for(int i=0;i<=500;i++)

{ g.setColor(Color.green); g.drawLine(i,0,500,500); i+=49;

}

Page 38: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

}}Output:

Page 39: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature

progr@m~82Aim:write a program to genret the to following diagram2

import java.applet.*;import java.awt.*;/*<applet code="design2" width="500" height="500"></applet>*/public class design2 extends Applet{public void init(){} public void paint (Graphics g) { g.setColor(Color.green); g.drawLine(10,10,60,60); g.setColor(Color.red); g.fillRect(70,70,50,50); g.setColor(Color.green); g.fillRect(120,120,50,50);

}}Output:

Page 40: svbitce2010.weebly.comsvbitce2010.weebly.com/.../8/4/4/5/8445046/java_51-82.docx · Web viewProgr@m~ 51. Aim: Write a program to create class with same name and different signature