Skip to main content

Posts

Showing posts from March, 2017

Practice Set: After MTE

1. Write a program to define a class Employee with attributes name, employee_id and salary and also provide a parameterized constructor to initialize all the attributes. Create an appropriate collection to store the Employee objects such that the non-duplicate objects are stored in descending order of their salary. Use Iterator to display the names and salary of all the employees. 2. WAP to create a class Student with attributes name and cgpa. Add at least 5 Student objects in an appropriate collection such that they are sorted in descending order on the basis of their cgpa. Display the names of all the students who are eligible for Verizon placement drive.   (Eligibility: cgpa >=7.5 ) 3. Write a program which prompts the user to enter N integers and store them in an arraylist. Now implement a method which accepts an arraylist containing duplicate values and returns a Collection having unique elements only.                         public Collection removeDupli

Brainstorming: Exception Handling

1. What is the output of this program? class MyException extends Exception {    MyException()      {     super("Exception Occured");      }    public String toString()      {     return "Problem";      } } class Output {    public static void main(String args[])      {     try {         throw new MyException();         }         catch(MyException e)         {         System.out.print(e);         }      } } A) Exception Occured B) MyException: Exception Occured C) Problem D) None of These 2. Identify the incorrect statement among the following. A) throw is used to explicitly throw a user defined exception. B) throws is used to specify that the method can throw exception c) Throwable is an abstract class which is parent of Exception. D) None of the above. 3. What will be the Output of the following Program? public class Test {    public static void main(String[] args)      {     int[] array = new int[2];     for (int i=0; i<2; i++)       {        try{         arra

MTE Practice Set

1. What will be the output of the following code snippet? int x=5, y=1; if(x++>5)    {     if(y<2) System.out.println("Hi");     else   System.out.println("Bye");    } else System.out.println("Oh"); A. Hi    B. Bye    C. Oh    D. Compilation Error Ans: C 2. What will be the output of the following code snippet?    if(!true) System.out.print("Hi ");       if(true) System.out.print("Hello ");       else System.out.println("Bye"); A. Hi Bye   B. Hello   C. Bye    D. Compilation Error         Ans: B 3. Which of the following is INCORRECT header for the main method in java? A. public static void main(String [] arg) B. static public void main(String arg []) C. public static void main(String...arg) D. None of These Ans: D 4. Which of the following is NOT a feature of Java? A. secure    B. platform-dependent    C. robust    D. multi-threaded Ans: B 5. Which of the following Java Edition is dedicated for Web-application developm

MTE Challenge-1

1. What will be the output of the following Program? class A {} class B extends A {    public void show()     {         System.out.println("Bye");     }    public static void main(String [] rk)     {         A a1 = new B();         a1.show();        } } A. Bye            B. Compilation Error    C. Runtime Error    D. None of These 2. What will be the output of the following Program? class A {     private A(){} } class B extends A {    B()     {     System.out.println("Bye");     }    public static void main(String [] rk)     {         A a1 = new B();        } } A. Bye            B. Compilation Error    C. Runtime Error    D. None of These 3. What will be the output of the following Program? class A   {    public void show()     {         System.out.println("Hi");     }   } class B extends A {    public void show()     {         System.out.println("Bye");     }    public static void main(String [] rk)     {         A a1 = new B();         a1.show