Beruflich Dokumente
Kultur Dokumente
Knowledge Byte
In this section, you will learn about:
NIIT
Collaborate Lesson 1C /
Collaborate
NIIT
Collaborate Lesson 1C /
Collaborate
NIIT
Collaborate Lesson 1C /
Collaborate
NIIT
Collaborate Lesson 1C /
Collaborate
NIIT
Collaborate Lesson 1C /
Collaborate
NIIT
Collaborate Lesson 1C /
Collaborate
NIIT
Collaborate Lesson 1C /
Collaborate
NIIT
Collaborate Lesson 1C /
Collaborate
NIIT
Collaborate Lesson 1C /
Collaborate
Best Practices
The Use of final Keyword
NIIT
Collaborate Lesson 1C /
Collaborate
Best Practices
The Use of final Keyword (Contd.)
NIIT
Collaborate Lesson 1C /
Collaborate
Best Practices
The Use of final Keyword (Contd.)
NIIT
Collaborate Lesson 1C /
Collaborate
Best Practices
The Use of final Keyword (Contd.)
NIIT
Collaborate Lesson 1C /
Collaborate
Tips
The Use of Constructors
NIIT
Collaborate Lesson 1C /
Collaborate
Tips
The finally Block
The finally block associated with a try block is executed after the try or catch
block is completed.
It is optional to associate the finally block with a try block, but if the try block
does not have a corresponding catch block, you should provide the finally
block.
NIIT
Collaborate Lesson 1C /
Collaborate
FAQs
Can classes inherit from more than one class in Java?
No, a class cannot be inherited from more than one class in Java. A class is
inherited from a single class only. However, multi-level inheritance is
possible in Java. For example, if class B extends class A and class C extends
class B, class C automatically inherits the properties of class A.
Both, class and interface, contain constants and methods. A class not only
defines methods but also provides their implementation. However, an
interface only defines the methods, which are implemented by the class that
implements the interface.
NIIT
Collaborate Lesson 1C /
Collaborate
FAQs (Contd.)
Do you have to catch all types of exceptions that might be thrown by Java?
Yes, you can catch all types of exceptions that are thrown in a Java
application using the Exception class.
How many exceptions can you associate with a single try block?
NIIT
Collaborate Lesson 1C /
Collaborate
FAQs (Contd.)
What are the disadvantages of inner classes?
The inner classes have various disadvantages. The use of inner class
increases the total number of classes in your code. The Java developers also
find it difficult to understand to implement the concept of inner class within
the programs.
NIIT
Collaborate Lesson 1C /
Collaborate
Challenge
1. You can access particular constructors in the superclass using
______operator.
2. Which of the following exceptions is raised when a number is divided by
zero:
a. NullPointerException
b. ArithmeticException
c. ArrayIndexOutOfBoundsException
d. NumberFormatException
3. You can have more than one finally block for an exception-handler.
(True/False)
4. Match the following:
a. public 1. Ensures the value is not changed in the classes that
implement an interface.
b. static 2. Ensures that are able to override the data members in
unrelated classes.
c. final 3. Ensures that you cannot create an object of the interface.
NIIT
Collaborate Lesson 1C /
Collaborate
Challenge (Contd.)
5. The following code is a jumbled code. Rearrange the following code to make it
executable:
public class Excp
{
public static void main(String args []) {
int num1, num2, num3;
num1 = 10;
num2 = 0;
catch(ArithmeticException e)
{
System.out.println(" Error Message");
} try
{
num3 = num1/num2;
}
NIIT
Collaborate Lesson 1C /
Collaborate
Solutions to Challenge
1. dot
2. b. ArithmeticException
3. False
4. a. 2
b. 1
c. 3
5. public class Excp
{
public static void main(String args [])
{
int num1, num2, num3;
num1 = 10;
num2 = 0;
NIIT
Collaborate Lesson 1C /
Collaborate
NIIT
Collaborate Lesson 1C /