Hide all answers
Hide all answers
View all answers
View all answers
Print
Try the Quiz
Learn Java programming through these flash cards. |
1. Consider the following application: class Max { public static void main(String args[ ]) { int max = 10; max(max, 20, 30); System.out.println(max); } static void max(int max, int x1, int x2) { if(x1 > x2) max = x1; else max = x2; } } What value is printed out, when executed?
Answer: 10 2. State the output of the following program: class Recur { public static void main(String args[ ]) { int Result = result(10); System.out.println("Result = " + Result); } static int result(int m) { if(m <= 2) return m; else return m + result(m-2); } }
Answer: 30 3. Consider the class definition: class Default { public static void main(String args[ ]) { int m; System.out.println("m is " + m); } } Will this code compile? Yes or No. Give reason, if No.
Answer: No
4. What is the output of the following program? class Static { static int m = 0; static int n = 0; public static void main(String args[ ]) { int m = 10; int x = 20; { System.out.println("m + n = " + m + n); } x = m + n; System.out.println("x = " + x); } }
Answer: m + n = 40; x = 10 5. Consider the following class definitions: class Square { private Square() { } int area(int side) { return(side * side); } } class Constructor { public static void main(String args[ ]) { Square S1 = new Square(); int area = S1.area(10); System.out.println(area); } } Will the code above compile and run successfully? Yes or No. Give reason, if No.
Answer: No 6. Write a statement to draw a rounded rectangle with the following features: width = 200 height = 100 corner horizontal diameter = 20 corner vertical diameter = 40 Select a suitable upper-left corner of the rectangle.
Answer: drawRoundRect(10,10,200,100,20,40); 7. Which line of the following HTML file contains an error? 1. < applet 2. WIDTH = 400 HEIGHT = 200 3. CODE = HelloJava.class > 4. < param 5. NAME = "string" 6. VALUE = "Hello" > 7.
Answer: Line 3 8. What is the output of the following program: class MainString { public static void main(String args[ ]) { StringBuffer s = new StringBuffer("String"); if(s.length()>5) && (s.append("Buffer").equals("X") ; // empty statement System.out.println(s); } }
Answer: StringBuffer 9. What is the range of the value that can be assigned to a variable of type long?
Answer: -263 to 263 - 1 10. Consider the following program: class Number { int x; void store(Number num) { num.x++; } } class MainNumber { public static void main(String args[ ]) { Number n = new Number(); n.x = 10; n.store(n); System.out.println(n.x); } } What is the output?
Answer: 11 11. Given the code: class Continue { public static void main(String args[ ]) { int m = 0; loop1: for(int i=0; i<10; i++) loop2: for(int j=0;j<10;j++) loop3: for(int k=0;k<10;k++) { System.out.println(++m); if( (k%10) == 0) continue loop2; } } } What is the last value printed?
Answer: 100 12. Can an abstract method be declared final? Yes or No. If No, give reason.
Answer: No 13. Can an abstract method be declared static? Yes or No. If No, give reason.
Answer: No 14. Consider the following try .... catch block: class TryCatch { public static void main(String args[ ]) { try { double x = 0.0; throw(new Exception("Thrown")); return; } catch(Exception e) { System.out.println("Exception caught"); return; } finally { System.out.println("finally"); } } } What will be the output?
Answer: Exception caught finally 15. Write a statement that would construct a 20 point bold Helvetica font.
Answer: new Font("Monospaced", Font.BOLD, 20);
Try the Quiz : Java Programming : Flash Cards III
|