FIRST TERM EXAMINATION [SEPT, 2015]
FIFTH SEMESTER [B.TECH]
JAVA PROGRAMMING. [ETCS-307]
Time. 1.5 Hours M.M. : 30
Note: QNo.1 is compulsory. Attempt any two from the remaining three quations,
Q.1. (@) What is method overriding in java? @)
Ans. Method Overriding in Java: If subclass (child class) has the same method
as declared in the parent class, it is known as method overriding in java.
In other words, if subclass provides the specific ‘implementation of the method that
has been provided by one of its parent class, i is known as method overriding.
Usage of java method overriding:
* Method overriding is used to provide specific implementation of a method that is
already provided by its super class.
* Method overriding is used for runtime polymorphism.
Example:
One of the simplest example ~ Here Boy class extends Human class. Both the
classes have a common method void eat(). Boy class is giving its own implementation to
the eat() method or in other words it is overriding the method eat().
class Human{
public void eat()
{
System.out.printin(“Human is eating”);
)
}
class Boy extends Human{
public void eat(){
System.out.printin(“Boy is eating”);
}
public static void main( String args[]) {
Boy obj = new Boy();
obj.eat();
)
}
Output:
Boy is eating 2
Q.1. (b) Difference between abstract class and interface?
Ans.
Abstract Classes Interfaces
. Abstract class can extend only one | Interface can extend any number of
class or one abstract class at a time | interfaces at a time :
Abstract class can extend froma | Interface can extend nly from an interface
class or
Interface can have only abstract methods82-2017 Fifth Semester, Java Programming
bos.close();
)
)
)
Q.8.(b) Remote Method Invocation
Ans. Refer Q.7,(b).(iv). End Term Examination December-2016 [Page no -32-2016)
Q.8.(c) Object Serialization
Ans. To serialize an object means to convert its state to a byte stream so that the
byte stream can be reverted back into a copy of the object. A Java object is serializable
if its class or any of its superclasses implements either’ the java.ioSerializable interface
or its subinterface, java.io.Externalizable. Deserialization is the process of converting
the serialized form of an object back into a copy of the object.
For example, the java.awt.Button class implements the Serializable interface, so
you can serialize a java.awt.Button object and store that serialized state in a file. Later,
you can read back the serialized state and deserialize into a java.awt.Button object
‘The Java platform specifies a default way by which serializable objects are
serialized. A (Java) class can override this default serialization and define its own way
of serializing objects of that class. The Object Serialization Specification describes object
serialization in detail.
When an objectis serialized, information that identifies its class is revorded in the
serialized stream. However, the class's definition (“class file”) itself is not recorded. It
> is the responsibility of the system that is deserializing the object to determine how
tol locate and load the necessary class files
Binding a Serializable Object: You can store a serializable object in the director)’
ifthe underlying service provider supports that action, as does Oracle's LDAP service;
provider.
‘The following example invokes Context.bind to bind an AWT button to the name
“cn=Button”. To associate attributes with the new binding, you use DirContext.bind. Tb
overwrite an existing binding, use Context.rebind and DirContext.rebind.
// Create the object to be bound
Button b = new Button(“Push me”);
// Perform the bind
ctx.bind(“cn=Button”, b);
You can then read the object back using Context.lookup,
// Check that it is bound
Button b2 = (Button)ctx.lookup(“en=Button”);
System.out.println(b2); /
Running this example produces the following output. ~
# javaSerObj :
java.awt Button[button0,0,0,0x0,invalid,label=Push me]
as follows.