Skip to main content

Programming Exercise for MTE

1. WAP to demonstrate the use of Anonymous class.

2. WAP to demonstrate the inheritance of class-class, interface-interface and interface-class.

3. WAP to calculate the sum of all the elements on the major diagonal of a square matrix using the following method:
public static int MajorDiagonal(int [][] arr)

4. WAP in which prompt the user to enter two numbers a and b. If a is divisible by b then throw NumberFormatException. Rethrow the exception from the catch block. And catch the re-thrown exception in a generalized catch block.

5. WAP to create a custom Exception class "TooLongException". Prompt the user to enter a String. If the length of String is greater than 10, then throw TooLongException.

6. WAP in which prompt the user to enter a number. If the number is less than 100 the throw an exception and display "Number is less than 10" and if it is greater than 20 then throw an exception and display "Number is greater than 20". Rethrow the exception in both the cases to print "Thanks".

7. 1. WAP in which Override the balance() of Bank class into Account class and invoke both the methods without using the object of Bank class.

8. WAP to demonstrate the use of this keyword in java.

9. WAP in which use method public int[] double_to_Int(double [] ar) to convert all the double values of argumented array into
int.

10. WAP to create a jagged Array in which rows and columns should be taken as input from user.

11. WAP to remove the last element from the arraylist.

12. WAP to demonstrate Constructor overloading..

13. WAP to delete the given element x from the array using method
                      public int [] delete(int x, int [] arr ).

14. WAP to calculate the sum of all the elements in a given row using the following method:
                      public static int RowSum (int row, int [][] arr)

15. WAP to create a class Demo containing a two overloaded methods demo(). Define a local class X containing show()in one of the demo() method. Access the show() from the other demo().

16. Define an interface B containing demo() method and a double variable x initialized with 20.0. Now create a class Test which inherits A and B. Invoke the demo() method and print the value of x. Explain the output.

17. WAP to create an ArrayList. Use a method public void reverseList() to reverse the order of ArrayList elements.

Comments

  1. what will be the program of 6th problem... i need it

    ReplyDelete
  2. Good Post! Thank you so much for sharing the nice 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

Practice MCQs

  1. What will be the Output of the following code? class X{                  static int x = 1;                        static class Y {                              static int y = x++;                                static class Z                                                                       {                                                                                         static int z = ++y;                                                                        }                                               }                }   class MainClass{     public static void main(String[] rk)    {                             System.out.print(X.x);                                             System.out.print(X.Y.y);                             System.out.print(X.Y.Z.z);         } } A. 113 B. 123 C. 111 D. None of These Ans: A 2.  Which of the following statement is TRUE about t he following code? public class Outer  {    private i

Practice Set

1. Write a program to create a class Voter which contains attributes name, date_of_birth and voter_id and voter has a Voter_Card. Provide appropriate constructor to initialize all the attributes of the Voter but voter id must be assigned automatically only when the age of the voter is greater than or equal to 18 years. VoterCard is a nested class with attributes voter_id and Voter_name. Make sure that voter card is created only when user is a valid voter and if it is already created then must not be assigned the new voter id. 2. Write a program to define two interfaces UGC and AICTE both having a default method int getAdmission() to take the admission and an abstract method String payFee(). getAdmission() in UGC must ask the percentage in qualifying exam and if the percentage >= 60 then generate the registration number and return. getAdmission() is AICTE must ask the user to join the counseling after 5 days and display the date of counseling and return the counseling token numb

Mock Test - 1

1. Which of the following is a byte stream class? A. ObjectInputStream B. Writer C. PrintWriter D. Scanner Ans: A 2. Which exception is thrown by read() method in InputStream class? A. IOException B. InterruptedException C. FileNotFoundException D. None of These Ans: A 3. Which of the following class is subclass of FilterInputStream? A. InputStream B. ObjectOutputStream C. FileInputStream D. BufferedInputStream  Ans: D 4. Which of these class contains the print() and println() methods? A. System B. out C. PrintStream D. BUfferedOutputStream Ans: C 5. Which of these is a method to clear all the data present in output buffer without terminating the stream? A. clear() B. fflush() C. flush() D. close() Ans: C 6. Which of these classes defined in java.io and used for file-handling are abstract? (i) InputStream        (ii) PrintStream    (iii) Reader        (iv) FileInputStream A. Only i     B. i and ii    C. Only iii    D. i and iii Ans: D 7. What is the output of this program? class MyE