1.What is the purpose of declaring a variable as final?
Ans: A final variable's value can't be changed. final variables should be initialized before using them.
2.What is the impact of declaring a method as final?
Ans: A method declared as final can't be overridden. A sub-class can't have the same method signature with a different implementation.
3.I don't want my class to be inherited by any other class. What should i do?
Ans: You should declared your class as final. But you can't define your class as final, if it is an abstract class. A class declared as final can't be extended by any other class.
4.What is finalize() method?
Ans: finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.
5.What are Transient and Volatile Modifiers?
Ans: Transient: The transient modifier applies to variables only and it is not stored as part of its object’s Persistent state. Transient variables are not serialized.
Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.
6.What is final, finalize() and finally?
Ans: final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method can’t be overridden. A final variable can’t change from its initialized value.
finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection.
finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown.
Ans: A final variable's value can't be changed. final variables should be initialized before using them.
2.What is the impact of declaring a method as final?
Ans: A method declared as final can't be overridden. A sub-class can't have the same method signature with a different implementation.
3.I don't want my class to be inherited by any other class. What should i do?
Ans: You should declared your class as final. But you can't define your class as final, if it is an abstract class. A class declared as final can't be extended by any other class.
4.What is finalize() method?
Ans: finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.
5.What are Transient and Volatile Modifiers?
Ans: Transient: The transient modifier applies to variables only and it is not stored as part of its object’s Persistent state. Transient variables are not serialized.
Volatile: Volatile modifier applies to variables only and it tells the compiler that the variable modified by volatile can be changed unexpectedly by other parts of the program.
6.What is final, finalize() and finally?
Ans: final : final keyword can be used for class, method and variables. A final class cannot be subclassed and it prevents other programmers from subclassing a secure class to invoke insecure methods. A final method can’t be overridden. A final variable can’t change from its initialized value.
finalize() : finalize() method is used just before an object is destroyed and can be called just prior to garbage collection.
finally : finally, a key word used in exception handling, creates a block of code that will be executed after a try/catch block has completed and before the code following the try/catch block. The finally block will execute whether or not an exception is thrown.
For example, if a method opens a file upon exit, then you will not want the code that closes the file to be bypassed by the exception-handling mechanism. This finally keyword is designed to address this contingency.
7.What is UNICODE?
Ans: Unicode is used for internal representation of characters and strings and it uses 16 bits to represent each other.
8.What is the difference between a public and a non-public class?
Ans: A public class may be accessed outside of its package.
A non-public class may not be accessed outside of its package.
9.To what value is a variable of the boolean type automatically initialized?
Ans: The default value of the boolean type is false.
10.What is the difference between the prefix and postfix forms of the ++ operator?
Ans: The prefix form performs the increment operation and returns the value of the increment operation.
The postfix form returns the current value all of the expression and then performs the increment operation on that value.
7.What is UNICODE?
Ans: Unicode is used for internal representation of characters and strings and it uses 16 bits to represent each other.
8.What is the difference between a public and a non-public class?
Ans: A public class may be accessed outside of its package.
A non-public class may not be accessed outside of its package.
9.To what value is a variable of the boolean type automatically initialized?
Ans: The default value of the boolean type is false.
10.What is the difference between the prefix and postfix forms of the ++ operator?
Ans: The prefix form performs the increment operation and returns the value of the increment operation.
The postfix form returns the current value all of the expression and then performs the increment operation on that value.
Previous | Next |
:: Click the links below for similar type Questions and answers ::
0 comments:
Post a Comment