Can A Class Extend More Than One Class?
Not possible. A Class can extend only one class but can implement any number of Interfaces.
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 it 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 Oo Concept Is Achieved By Using Overloading And Overriding?
Polymorphism.
If I Only Change The Return Type, Does The Method Become Overloaded?
No it doesn't. There should be a change in method arguements for a method to be overloaded.
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) and readExternal(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.
What Value Does Read() Return When It Has Reached The End Of A File?
The read() method returns -1 when it has reached the end of a file.
Can A Byte Object Be Cast To A Double Value?
No, an object cannot be cast to a primitive value.
What Is The Difference Between A Static And A Non-static Inner Class?
A non-static inner class may have object instances that are associated with instances of the class's outer class. A static inner class does not have any object instances.
What Is An Object's Lock And Which Object's Have Locks?
An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock. All objects and classes have locks. A class's lock is acquired on the class's Class object.
What Is The % Operator?
It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand.
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.
Which Class Is Extended By All Other Classes?
The Object class is extended by all other classes.
Which Non-unicode Letter Characters May Be Used As The First Character Of An Identifier?
The non-Unicode letter characters $ and _ may appear as the first character of an identifier.
What Restrictions Are Placed On Method Overloading?
Two methods may not have the same name and argument list but different return types.
What Is Transient Variable?
Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable can't be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null.
What Is Collection Api?
The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces.
Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.
Example of interfaces: Collection, Set, List and Map.
What Is Casting?
There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.
What Is The Return Type Of A Program's Main() Method?
void.
If A Variable Is Declared As Private, Where May The Variable Be Accessed?
A private variable may only be accessed within the class in which it is declared.
What Do You Understand By Private, Protected And Public?
These are accessibility modifiers. Private is the most restrictive, while public is the least restrictive. There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package.
What Is Downcasting ?
Downcasting is the casting from a general to a more specific type, i.e. casting down the hierarchy.
What Modifiers May Be Used With An Inner Class That Is A Member Of An Outer Class?
A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.
How Many Bits Are Used To Represent Unicode, Ascii, Utf-16, And Utf-8 Characters?
Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.
What Restrictions Are Placed On The Location Of A Package Statement Within A Source Code File?
A package statement must appear as the first line in a source code file (excluding blank lines and comments).
What Is A Native Method?
A native method is a method that is implemented in a language other than Java.
What Are Order Of Precedence And Associativity, And How Are They Used?
Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left.
Can An Anonymous Class Be Declared As Implementing An Interface And Extending A Class?
An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.
What Is The Range Of The Char Type?
The range of the char type is 0 to 2^16 - 1.
What Is The Range Of The Short Type?
The range of the short type is -(2^15) to 2^15 - 1.
Why Isn't There Operator Overloading?
Because C++ has proven by example that operator overloading makes code almost impossible to maintain.
Not possible. A Class can extend only one class but can implement any number of Interfaces.
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 it 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.
Appian Corporation Most Frequently Asked Core Java Interview Questions Answers |
What Is A Marker Interface?
An Interface which doesn't have any declaration inside but still enforces a mechanism.
Which Oo Concept Is Achieved By Using Overloading And Overriding?
Polymorphism.
If I Only Change The Return Type, Does The Method Become Overloaded?
No it doesn't. There should be a change in method arguements for a method to be overloaded.
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) and readExternal(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.
What Value Does Read() Return When It Has Reached The End Of A File?
The read() method returns -1 when it has reached the end of a file.
Can A Byte Object Be Cast To A Double Value?
No, an object cannot be cast to a primitive value.
What Is The Difference Between A Static And A Non-static Inner Class?
A non-static inner class may have object instances that are associated with instances of the class's outer class. A static inner class does not have any object instances.
What Is An Object's Lock And Which Object's Have Locks?
An object's lock is a mechanism that is used by multiple threads to obtain synchronized access to the object. A thread may execute a synchronized method of an object only after it has acquired the object's lock. All objects and classes have locks. A class's lock is acquired on the class's Class object.
What Is The % Operator?
It is referred to as the modulo or remainder operator. It returns the remainder of dividing the first operand by the second operand.
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.
Which Class Is Extended By All Other Classes?
The Object class is extended by all other classes.
Which Non-unicode Letter Characters May Be Used As The First Character Of An Identifier?
The non-Unicode letter characters $ and _ may appear as the first character of an identifier.
What Restrictions Are Placed On Method Overloading?
Two methods may not have the same name and argument list but different return types.
What Is Transient Variable?
Transient variable can't be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable can't be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null.
What Is Collection Api?
The Collection API is a set of classes and interfaces that support operation on collections of objects. These classes and interfaces are more flexible, more powerful, and more regular than the vectors, arrays, and hashtables if effectively replaces.
Example of classes: HashSet, HashMap, ArrayList, LinkedList, TreeSet and TreeMap.
Example of interfaces: Collection, Set, List and Map.
What Is Casting?
There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference.
What Is The Return Type Of A Program's Main() Method?
void.
If A Variable Is Declared As Private, Where May The Variable Be Accessed?
A private variable may only be accessed within the class in which it is declared.
What Do You Understand By Private, Protected And Public?
These are accessibility modifiers. Private is the most restrictive, while public is the least restrictive. There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package.
What Is Downcasting ?
Downcasting is the casting from a general to a more specific type, i.e. casting down the hierarchy.
What Modifiers May Be Used With An Inner Class That Is A Member Of An Outer Class?
A (non-local) inner class may be declared as public, protected, private, static, final, or abstract.
How Many Bits Are Used To Represent Unicode, Ascii, Utf-16, And Utf-8 Characters?
Unicode requires 16 bits and ASCII require 7 bits. Although the ASCII character set uses only 7 bits, it is usually represented as 8 bits. UTF-8 represents characters using 8, 16, and 18 bit patterns. UTF-16 uses 16-bit and larger bit patterns.
What Restrictions Are Placed On The Location Of A Package Statement Within A Source Code File?
A package statement must appear as the first line in a source code file (excluding blank lines and comments).
What Is A Native Method?
A native method is a method that is implemented in a language other than Java.
What Are Order Of Precedence And Associativity, And How Are They Used?
Order of precedence determines the order in which operators are evaluated in expressions. Associatity determines whether an expression is evaluated left-to-right or right-to-left.
Can An Anonymous Class Be Declared As Implementing An Interface And Extending A Class?
An anonymous class may implement an interface or extend a superclass, but may not be declared to do both.
What Is The Range Of The Char Type?
The range of the char type is 0 to 2^16 - 1.
What Is The Range Of The Short Type?
The range of the short type is -(2^15) to 2^15 - 1.
Why Isn't There Operator Overloading?
Because C++ has proven by example that operator overloading makes code almost impossible to maintain.
Post a Comment