• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Serialization

 
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.io.*;
class A
{

A(String s)
{

System.out.println("ssds'");
}
}
class B1111 extends A
{
int x;
B1111(String s)
{
super(s);
System.out.println("Hello World B1111 !");
}

public static void main(String[] args)
{ try
{
System.out.println("Hello World!");
FileOutputStream fos = new FileOutputStream("test");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(new B1111("sas"));
}
catch(Exception e)
{}


}
}
Will it give o/p or run time error since B1111 doesn't implements serializable
I am getting output
Hello world
ssds
Hello world b1111
 
Rancher
Posts: 43028
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This is not a good idea. How will you know if there is an exception? That's what you want to find out, isn't it?
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you will get a runtime Exception ::

java.io.NotSerializableException: B1111
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
at B1111.main(B1111.java:26)



you aren't seeing this exception because in
catch(Exception e) {}
you aren't printing anything so change it to
catch(Eception e) { e.printStackTrace(); }
 
V Gala
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
 
An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic