package SJCPTest;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class SerialTest {
public static void main(String a[])
{
Dog ob=new Dog(50,"Puppy");
ob.change();
try {
FileOutputStream fo=new FileOutputStream("obj.ser");
ObjectOutputStream oo=new ObjectOutputStream(fo);
oo.writeObject(ob);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
FileInputStream fi=new FileInputStream("obj.ser");
ObjectInputStream oi=new ObjectInputStream(fi);
Dog newob=(Dog)oi.readObject();
System.out.println("Weight:"+newob.weight);
System.out.println("Name:"+newob.name);
System.out.println("Static Variable tmp:"+newob.tmp);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
class Animal
{
int weight;
Animal()
{
this.weight=100;
}
}
class Dog extends Animal implements Serializable
{
String name;
static int tmp;
Dog(int weight,String name)
{
//super(weight);
this.weight=weight;
this.name=name;
tmp=77;
}
public void change()
{
weight=100;
}
}
This code results
Weight:100
Name:Puppy
Static Variable tmp:77
I don't know how it results tmp as 77?
Somebody make me clear about this..
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaprogrammingwithpassion?hl=en