core java Question

49. 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.

50. Can an Interface be final?
Not possible. Doing so so will result in compilation error.

51. Can a class be defined inside an Interface?
Yes it's possible.

52. Can an Interface be defined inside a class?
Yes it's possible.

53. What is a Marker Interface?
An Interface which doesn't have any declaration inside but still enforces a mechanism.

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

55. 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.

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

57. 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) and readExternal(ObjectInput in)

58. What modifiers are allowed for methods in an Interface?
Only public and abstract modifiers are allowed for methods in interfaces.

59. 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.

60. What is an abstract method?
An abstract method is a method whose implementation is deferred to a subclass.

Jump to page : 1 |2  | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 

0 comments:

Post a Comment