StuffArrow is under maintenance. These are the demo deals and offers you are seeing here. We will come up with fresh and live deals and offers soon. Thanks for your patience. Keep visit our site for updates

Interfaces and Abstraction Questions

What is an Abstract Class and what is its purpose?

A Class which doesn’t provide complete implementation is defined as an abstract class. Abstract classes enforce abstraction.

 

Can a abstract class be declared final?

Not possible. An abstract class without being inherited is of no use and hence will result in compile time error.

What is use of a abstract variable?

Variables can’t be declared as abstract. only classes and methods can be declared as abstract.

Can you create an object of an abstract class?

Not possible. Abstract classes can’t be instantiated.

 

Why is an Interface be able to extend more than one Interface but a Class can’t extend more than one Class?

Basically Java doesn’t allow multiple inheritance, so a Class is restricted to extend only one class. But an Interface is a pure abstraction model and doesn’t have inheritance hierarchy like classes (do remember that the base class of all classes is Object). So an Interface is allowed to extend more than one Interface.

Can an Interface be final?

Not possible. Doing so will result in compilation error.

Can a class be defined inside an Interface?

Yes it’s possible.

Can an Interface be defined inside a class?

Yes it’s possible.

What is a Marker Interface?

An Interface which doesn’t have any declaration inside but still enforces a mechanism.

Which object oriented Concept is achieved by using overloading and overriding?

Polymorphism.

 

Why does Java not support operator overloading?

Operator overloading makes the code very difficult to read and maintain. To maintain code simplicity, Java doesn’t support operator overloading.

 

Can we define private and protected modifiers for variables in interfaces?

No.

What is Externalizable?

Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) andreadExternal(ObjectInput in)

What modifiers are allowed for methods in an Interface?

Only public and abstract modifiers are allowed for methods in interfaces.

What is a local, member and a class variable?

Variables declared within a method are “local” variables.

Variables declared within the class i.e. not within any methods are “member” variables (global variables).

Variables declared within the class i.e. not within any methods and are defined as “static” are class variables.

What is an abstract method?

An abstract method is a method whose implementation is deferred to a subclass.

When can an object reference be cast to an interface reference?

An object reference be cast to an interface reference when the object implements the referenced interface.

 

Can a abstract class be defined without any abstract methods?

Yes it’s possible. This is basically to avoid instance creation of the class.

 

Can a method inside a Interface be declared as final?

No not possible. Doing so will result in compilation error. public and abstract are the only applicable modifiers for method declaration in an interface.

Can an Interface implement another Interface?

Interfaces doesn’t provide implementation hence a interface cannot implement another interface.

Can an Interface extend another Interface?

Yes an Interface can inherit another Interface, for that matter an Interface can extend more than one Interface.

Can a Class extend more than one Class?

Not possible. A Class can extend only one class but can implement any number of Interfaces.

 

Newsletter

%d bloggers like this: