0% found this document useful (0 votes)
19 views1 page

Java Packages, Interfaces, and Exception Handling

This document contains questions about Java packages, interfaces, exceptions, and exception handling. It also includes practical programming questions to demonstrate these concepts. Some key points covered are: - Packages are used to organize Java code and avoid naming conflicts. There are predefined and default packages. - Interfaces cannot have variables but can inherit other interfaces. They define method signatures without implementations. - Abstract classes can have variables and methods while interfaces only define method signatures. - Exceptions require special handling to prevent program crashes and ensure expected behavior. There are different exception types and a base Exception class. - Finally blocks are used to ensure cleanup code runs even if an exception occurs.

Uploaded by

Ishan Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views1 page

Java Packages, Interfaces, and Exception Handling

This document contains questions about Java packages, interfaces, exceptions, and exception handling. It also includes practical programming questions to demonstrate these concepts. Some key points covered are: - Packages are used to organize Java code and avoid naming conflicts. There are predefined and default packages. - Interfaces cannot have variables but can inherit other interfaces. They define method signatures without implementations. - Abstract classes can have variables and methods while interfaces only define method signatures. - Exceptions require special handling to prevent program crashes and ensure expected behavior. There are different exception types and a base Exception class. - Finally blocks are used to ensure cleanup code runs even if an exception occurs.

Uploaded by

Ishan Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Assignment 5 Covers: Package, Interface, and Exception Handling Theory Questions 1.

What are packages and why they are used in Java? What are the various types of packages? 2. List down the names of any 5 pre-defined packages and which one is the default package that gets imported in every java program. 3. What are the various variants of import? What all is imported when we write import package.*? 4. What is an interface? Can interface have variables? Can one interface inherit another interface? 5. What is the difference between an abstract class and an interface? 6. How are packaged programs compiled and interpreted? 7. Why do we require Exceptional Handling? Describe the various constructs and statements used for Exception Handling? 8. How does Exception Handling differs from Exception Forwarding? Which approach according to you is better and why? 9. What are the various types of Exception? Which is their base class? 10. Give examples of any 3 exceptions thrown by Java, also explain how they can be handled. Practical Questions 1. Create a class called Abc within a package called mypack, create another class called Xyz within the same package. Write main within class Xyz , in which create an object of Abc. Compile and execute it. 2. Create the following class hierarchy and perform the following operations: a. Write main within class MainProg that creates object of Abc, Xyz, Efg and Lmn and execute it. b. Write main within Xyz that creates objects of Lmn and Efg and execute it.

hospital (MainProg) patients (Abc) regular (Efg) staff (Xyz) visiting (Lmn)

3. Write a program that accepts a number as command line argument and display its table. Handle all possible exceptions. If the number is greater than 25 it should generate a custom exception. 4. Create a function that takes a number as input and returns its cube, if the number is greater than 100 it generates NoCubeException. Write a program that accepts a number as command line argument and print its cube using the function created. 5. In both the above programs try to use finally.

[Link]

Software Consultancy, Development and Training

You might also like