1.
a) Multi threading
import [Link].*;
class pen extends Thread
{
int i;
public void run()
{
try
{
for(i=0;i<=5;i++)
{
[Link]("Abarna");
[Link](5000);
}
}
catch(Exception c)
{
[Link]("Abarna");
}
}
}
class multithread1
{
public static void main(String s[])throws IOException
{
pen pencil=new pen();
[Link]();
}
}
1.B (multi level inheritance)
import [Link].*;
class lion{
int a,b,c;
DataInputStream paper=new DataInputStream([Link]);
void red()throws IOException
{
[Link]("Enter the a value : ");
a=[Link]([Link]());
[Link]("Enter the b value : ");
b=[Link]([Link]());
}
}
class tiger extends lion
{
String v;
int w;
void green()throws IOException
{
if(a==b)
{
c=a+b;
[Link]("the answer is: "+c);
}
else
{
c=a-b;
[Link]("the answer is: "+c);
}
}
}
class cheeta extends tiger
{
int k;
void orange()throws IOException
{
for(w=0;w<c;w++)
{
[Link]("kasthu");
}
}
}
class leo extends cheeta
{
int q;
void yellow()throws IOException
{
[Link]("kasthu");
[Link]("Enter mom age :");
k=[Link]([Link]());
[Link]("Enter dad age :");
q=[Link]([Link]());
[Link]("Enter your family name :");
v=[Link]();
}
}
class multiinheritance1b
{
public static void main(String R[])throws IOException
{
leo pen= new leo();
[Link]();
[Link]();
[Link]();
[Link]();
}
}
2.A)Constructor
import [Link].*;
class keyboard
{
int a,b,c;
DataInputStream pencil=new DataInputStream([Link]);
void keyboard()throws IOException
{
int a,b,c;
[Link]("Enter the a value:");
a=[Link]([Link]());
[Link]("Enter the b value:");
b=[Link]([Link]());
}
}
interface abarna
{
void pink()throws IOException;
}
class mouse extends keyboard implements abarna
{
public void pink()throws IOException
{
c=a+b;
[Link]("The answer is:"+c);
}
}
class constructor2a
{
public static void main(String a[])throws IOException
{
mouse bat=new mouse();
[Link]();
[Link]();
}
}
2.b) Exception handling
import [Link].*;
class keyboard
{
int a,b,c;
DataInputStream pencil=new DataInputStream([Link]);
void blue()throws IOException
{
try
{
[Link]("a value:");
a=[Link]([Link]());
[Link]("b value:");
b=[Link]([Link]());
}
catch(Exception e)
{
[Link]("YOU entered the string !!!!");
}
}
}
interface abarna
{
void pink()throws IOException;
}
class mouse extends keyboard implements abarna
{
public void pink()throws IOException
{
c=a+b;
[Link]("The answer is:"+c);
}
}
class exceptionHandling2b
{
public static void main(String a[])throws IOException
{
mouse bat=new mouse();
[Link]();
[Link]();
}
}
3.a) Interface
import [Link].*;
class keyboard
{
int a,b,c;
DataInputStream pencil=new DataInputStream([Link]);
void blue()throws IOException
{
[Link]("a value:");
a=[Link]([Link]());
[Link]("b value:");
b=[Link]([Link]());
}
}
interface abarna
{
void pink()throws IOException;
}
class mouse extends keyboard implements abarna
{
public void pink()throws IOException
{
c=a+b;
[Link]("The answer is:"+c);
}
}
class interf3a
{
public static void main(String a[])throws IOException
{
mouse bat=new mouse();
[Link]();
[Link]();
}
}
3.b) Classes and objects
import [Link].*;
class blue
{
void apple()throws IOException
{
int a,b,c;
DataInputStream book=new DataInputStream([Link]);
[Link]("Enter the a value:");
a=[Link]([Link]());
[Link]("Enter the b value:");
b=[Link]([Link]());
c=a+b;
[Link]("The addition is:"+c);
}
}
class black
{
void mango()throws IOException
{
int a,b,c;
DataInputStream book=new DataInputStream([Link]);
[Link]("Enter the a value:");
a=[Link]([Link]());
[Link]("Enter the b value:");
b=[Link]([Link]());
c=a-b;
[Link]("The subraction is:"+c);
}
}
class red
{
void grape()throws IOException
{
int a,b,c;
DataInputStream book=new DataInputStream([Link]);
[Link]("Enter the a value:");
a=[Link]([Link]());
[Link]("Enter the b value:");
b=[Link]([Link]());
c=a*b;
[Link]("The multiplication is:"+c);
}
}
class green
{
void kiwi()throws IOException
{
int a,b,c;
DataInputStream book=new DataInputStream([Link]);
[Link]("Enter the a value:");
a=[Link]([Link]());
[Link]("Enter the b value:");
b=[Link]([Link]());
c=a/b;
[Link]("The division is:"+c);
}
}
class classesandobjects3b
{
public static void main(String z[])throws IOException
{
blue pen=new blue();
black pencil=new black();
red eraser=new red();
green scale=new green();
[Link]();
[Link]();
[Link]();
[Link]();
}
}
5.b)Package
package hackbal;
public class hackbal
{
Public void pink()
{
[Link](“Welcome”);
}
Public void blue()
{
[Link](“TO”);
}
}
import [Link].*;
import hackbal.*;
class aboutus extends hackbal
{
void yellow()
{
[Link](“BCA”);
}
public static void main(String a[])throws IOException
{
aboutus pen=new aboutus();
[Link]();
[Link]();
[Link]();
}
}
6.a) Array
Import [Link].*;
Class array
{
public static void main(String a[])throws IOException
{
int b[]={1,2,1};
int c[]=new int[5];
DataInputStream in=new DataInputStream([Link]);
[Link](“What is your favourite subject:”);
[Link](“[Link] [Link] [Link]”);
C[0]=[Link]([Link]());
If(c[0]==b[0])
{
[Link](“Your answer is correct”);
}
Else
{
[Link](“Your answer is wrong”);
}
[Link](“What is your favourite fruit:”);
[Link](“[Link] [Link] [Link]”);
C[1]=[Link]([Link]());
If(c[1]==b[1])
{
[Link](“Your answer is correct”);
}
Else
{
[Link](“Your answer is wrong”);
}
[Link](“What is your favourite movie:”);
[Link](“[Link] [Link] [Link]”);
C[0]=[Link]([Link]());
If(c[0]==b[0])
{
[Link](“Your answer is correct”);
}
Else
{
[Link](“Your answer is wrong”);
}
}
}