OOPJ IMP 2 - VisionPapers - in
OOPJ IMP 2 - VisionPapers - in
Example:
class a
{
int i;
}
class b extends a
{
Void display()
{
System.out.println(“the value of I is =”+i);
}
}
class singledemo
{
public static void main(String args[])
{
b b1=new b();
b1.i=7;
b1.display();
}
}
System.out.println(“I in class b”+j);
}
}
class c extends b
{
void sum()
{
System.out.println(“the sum is ”+(i+j));
}
}
class MultilevelDemo
{
public static void main(String args[])
{
b b1=new b();
b1.i=5;
c c1=new c();
c1.display();
c1.i=10;
c1.j=20;
c1.sum();
}
}
Example:
interface A
{
int i=10;
}
interface B
{
int j=20;
}
class C implements A,B
{
void sum()
{
System.out.println(“the sum is ”+(i+j));
}
}
class InterFaceDemo
{
public static void main(String args[])
{
C c1=new C();
c1.sum();
}
}
1) New born state
When we create a thread object, the thread is born and is said to be in newborn
state.
The thread is not still scheduled for running.
2) Runnable state
Running means that processor has given its time to the thread for its execution.
A running thread may change its state to another state using resume (), modify
(), sleep (), wait () methods etc.
4) Blocked state
Every thread has a life cycle. A running thread ends its life when it has
completed executing its run ( ) method.
It is natural death. However we can kill it by sending the stop message to it as
any state thus causing a premature death for it.
Throws
The Java throws keyword is used to declare an exception.
If a method does not handle a checked exception, the method must declare it using the
throws keyword.
The throws keyword appears at the end of a method’s signature.
You can declare multiple exceptions.
Syntax:
return_type method_name () throws exception_class_name
{
//method code
}
Example:
import java.io.*;
class M
{
void method()throws IOException
{
throw new IOException("device error");
}
}
public class Testthrows2
{
public static void main(String args[])
{
try
{
M m=new M ();
m.method();
}
catch(Exception e)
{
System.out.println("exception handled");
}
System.out.println("normal flow...");
}
}