Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4029180
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:18:46+00:00 2026-05-20T11:18:46+00:00

public class Foo implements java.io.Serializable { private int v1; private static double v2; private

  • 0
public class Foo implements java.io.Serializable {
   private int v1;
   private static double v2;
   private Loan v3 = new Loan();
}

Options:
A. An instance of Foo can be serialized because Foo implements Serializable.
B. An instance of Foo cannot be serialized because Foo contains a non-serializable instance variable v3.
C. If you mark v3 as transient, an instance of Foo is serializable.
D. b and c

Answer: D

Explanation: An object may not be serialized even though its class implements java.io.Serializable, because it may contain non-serializable instance variables.

Now my question is:

As far as I know, transient is used to turn off serialization. Then how is transient in this case, helping us to serialize foo?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:18:47+00:00Added an answer on May 20, 2026 at 11:18 am

    transient doesn’t disable serialization altogether; it just marks members that won’t be serialized. It’s typically used for stuff that would be incorrect or irrelevant when the object is unserialized, or stuff that it’d be less-than-safe to store (passwords, decrypted data, that sort of thing), or non-serializable stuff that could be easily reconstructed.

    In this case, i assume the Loan class isn’t serializable. (If it were, then A would be correct.) Marking v3 as transient just tells Java not to worry about that field, but go ahead and serialize the others. This means an unserialized Foo might have a null v3. If you want to store the Loan as well, you’d need to either keep track of enough info to recreate it at will, or change class Loan so that it implements java.io.Serializable as well.

    Alternatively, there are methods you could implement (writeObject, readObject) if you need control over serialization. But that can be a bit of a hassle.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following Java class: public class Foo { public static void doStuff() {
For example public interface X{ public void foo(X i); } public class Y implements
class Foo(){ public List<string> SomeCollection; } I need to implement an event which can
Given the following class public class Foo { public int FooId { get; set;
As an example: public class Foo { private Foo() {} } public class Bar
Assuming the following class stub: public class Foo<T> { private Class<T> type; public Foo<T>
I have a class like this public class foo { private void getThread() {
I'm having a basic Spring Controller package org.foo; @Controller public class HelloWorldController implements IHelloWorldController
I have the simple class using auto-implemented properies: Public Class foo { public foo()
Consider the following class hierarchy: public class Foo { public string Name { get;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.