Java Assingment1
Java Assingment1
205 IIIrd semester 2011-2012 Jagan Institute of Management Studies Deadline:- 20th sept 2011 1. Explain the usage of each of the following keywords. a) Final b) Abstract c) Static d) Finalize e) super 2. Differentiate between the following with examples. a) throw and throws b) call by value and call by reference c) Compile time polymorphism and Run time polymorphism 3. What is the error in the following programs? Write output if correct. a) public class ABC { public static void main(String[] args) { if (true) if(false) System.out.println("a"); else System.out.println("b found"); } } b) public class XYZ { public static void main(String[] args) { int x; switch(x) { case 2: case 1: case 0: default: case 4:
} } c) Class test { public static void main(String []args) { try { double x=0.0; throw new exception(Thrown); } catch(Exception e) { System.out.println(Exception caught+e); } finally { System.out.println(finally); } } } d) public class test { public static void main(String[] args) { int a1=18; int a2=35; int a3=50; int a4=44; double avg=(a1+a2+a3+a4)/4; System.out.println(avg); } } 4. Create a class named Addition having the following overloaded functions: int add(int , int) double add(double, double) String add(String, String) int add(int []) 5. Design an abstract class named Figure to represent any 2D figure. Inherit this class to represent the class representing Circle. Further, inherit the class circle to represent a 3D figure, sphere. Include Run time polymorphism through the functions to calculate area and perimeter of the figures