Skip to main content

Mocke Test: Exception Handling

1. Differentiate between throw and throws keywords in java using an appropriate program. 

 2. What is the difference between checked and unchecked exception? What are the different ways of handling checked exceptions in Java?


3. What is the significance of using finally block in exception handling? How it is different from the catch block? Explain the importance of finally with the help of a suitable program.


4.  Write a Program in which prompt the user to enter a String. If the size of String is odd, then throw a User-defined exception InvalidStringException and display "String is Not Accepted". Re-throw the caught exception from catch block to print "Thanks for using this Program".


5. Write a program to define a class named Car with an attribute fuel, and constants mileage and max_fuel. Provide the following methods:  

    public int addFuel(int ltr) throws FuelTankFullException
    public void travel(int km) throws NotSufficientFuelException


such that if the added fuel(ltr) is greater than max_fuel then a user defined exception FuelTankFullException is thrown and when the fuel is not sufficient to travel km distance then NotSufficientFuelException is thrown.

In main class create a Car object. Invoke the addFuel and travel methods. In travel method, handle the NotSufficientFuelException such that it asks the user to add the fuel.

Comments

  1. COEPD LLC - Center of Excellence for Professional Development is the most trusted online training platform to global participants. We are primarily a community of Business Analysts who have taken the initiative to facilitate professionals of IT or Non IT background with the finest quality training. Our trainings are delivered through interactive mode with illustrative scenarios, activities and case studies to help learners start a successful career. We impart knowledge keeping in view of the challenging situations individuals will face in the real time, so that they can handle their job deliverables with at most confidence.

    coepd.us/index.html

    ReplyDelete
  2. Good Post! Thank you so much for sharing the post, it was so good to read and useful to improve
    Java Training in Electronic City

    ReplyDelete

Post a Comment

Popular posts from this blog

ETE Practice Set-1

                                                                 Mock Test-1 -----------------------------------------------------------------------------------------------------------------------------   1 (a) Write a program that reads 10 integers between 1 and 100 and counts the occurrences of each. Assume the input ends with 0.                                                         ...

Practice Set: Unit-4

                                                                                                                Practice Set: Unit 4 1. What are the uses of super keyword in Java? Explain with a suitable example. 2. What are the various uses of final keyword in java? An abstract method can not be declared final. Why? 3. Differentiate between Abstract class and Interface. What do you mean by Functional interface and Lambda Expression?  ...

OLA-UBER Problem

Create two interfaces OLA and UBER both having a method public static Cab getCab() which returns the Cab object where Cab is a nested class inside OLA and UBER. Cab must have attributes cab_number and driver_name. A user rides 5 times using cabs of OLA and UBER randomly which are stored in an array. Now implement a method which should display the name of the driver and the company name i.e. OLA/UBER when the valid cab_number is entered by the user. Display "Invalid CAB details" when the cab_number entered by the user is incorrect.