Java Interview Questions and Answers - 5

25. How can we restrict certain variables of a class from getting serialized?

We can do so by using the keyword transient while declaring variables of the class.  

For example, the variable trans_count below is a transient variable and can't be serialized:

Example

public class transientSample {
    private transient trans_count;
}

26. Is it possible to use a default constructor even if an explicit constructor is defined?

When an explicit constructor is defined, default constructor can't be invoked. Java invokes default constructor when no explicit constructor is defined

27. Can we override a method by using same method name and arguments but different return types?

For a method to be overriden method name, arguments and return type must be exactly same. so, using a different return type doesn't override a method.