Sasuke_Uchiha

Practice Exam for JAVA Terminal

Jul 1st, 2019
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.40 KB | None | 0 0
  1. Questions 1: Select the right option. (10)
  2. 1) Every enum constant is always implicitly
  3. a) public
  4. 2) static
  5. 3) final
  6. 4) all three.
  7.  
  8. 2) A layout is placed on ____ to be displayed. (JavaFX)
  9. a) Stage
  10. b) Scene
  11. c) Group
  12. d) Parent
  13.  
  14. 3) Button class is a subclass of ____
  15. a) Node
  16. b) Label
  17. c) Scene
  18. d) Window
  19.  
  20. 4) We can create a reference variable of ____
  21. a) Class
  22. b) Interface
  23. c) Both
  24.  
  25. 5) Can we use the instance variable of class in that static variable of the same class?
  26. a) Yes
  27. b) No
  28. c) We need to create its object
  29. d) Just using class name would work.
  30.  
  31. 6) Static methods can refer to
  32. a) this
  33. b) super
  34. c) none of these
  35. d) both
  36.  
  37. 7) Which of these are valid in an interface
  38. a) static int x() { /*MuHaHaHa*/}
  39. b) int x = 0;
  40. c) double hello();
  41. d) all of these.
  42. e) none of these.
  43.  
  44. 8) Which exception must be caught if it's thrown by a method
  45. a) Run time Exception.
  46. b) Compile time Exception.
  47. c) None.
  48. d) Both.
  49.  
  50. 9) JCheckBox specialty is:
  51. a) Only one in the group can be selected.
  52. b) All can be selected at once.
  53. c) They make a beep sound when selecting by default.
  54. d) none just like normal list selection buttons.
  55.  
  56. 10) What can be used for placing the components in java swing:
  57. a) JPane
  58. b) JFrame
  59. c) JTextArea
  60. d) a and b.
  61. e) a and c.
  62. f) a,b and c.
  63. g) none.
  64.  
  65. Question 2: Short questions (6)
  66. What is the difference between VBox, HBox, and StackPane (JavaFX)? (3)
  67.  
  68. What is the difference between ArrayList and simple array, how to declare it and give its example? (3)
  69.  
  70. Question 3: Find the compile-time errors and fix them (10)
  71.  
  72. Code 1: (2)
  73. public static int sum(int x, int y) throws IOException
  74. {
  75. throw new IOException("Error ha");
  76. }
  77.  
  78. public static void main(String args[])
  79. {
  80. sum(1,2);
  81. }
  82.  
  83. Code 2: (2)
  84. float f = 8.0;
  85. double d = 7.0;
  86. int i = 0;
  87.  
  88. public void justAnMethod() {
  89. System.out.printf("%f,%d,%i",f,d,i);
  90. }
  91.  
  92. code 3: (2)
  93. import javax.swing.*;
  94. import java.awt.event.ActionListener;
  95.  
  96. public class MyFrame extends JFrame implements ActionListener
  97. {
  98. public MyFrame()
  99. {
  100. super();
  101.  
  102. }
  103. }
  104.  
  105. code 4: (4)
  106. public interface A {
  107. void hello();
  108. }
  109.  
  110. public class B {
  111. abstract public void bye();
  112. }
  113.  
  114. public class C extends B implements A {
  115. public void hello() {
  116. return;
  117. }
  118. }
  119.  
  120. public class D extends C implements A {
  121. @Override
  122. public void bye() {
  123.  
  124. }
  125.  
  126. @Override
  127. public void hello() {
  128.  
  129. }
  130. }
  131.  
  132. Question 4: (4)
  133. Your connection has been established to the database and stored in variable 'connection';
  134. Store data in table and then load all the data.
  135. When you have loaded all the data print only the data which you just added.
  136. Queries to use:
  137. For Saving:
  138. INSERT INTO Account (Name,Pass,Date) VALUES ('Arose','Niazi',NOW())
  139. For Loading:
  140. SELECT * FROM Account
  141.  
  142.  
  143. Question 5: (10)
  144. Write a paint program, keep it simple just too one color.
  145.  
  146. Question 6: (10)
  147. Determine the output
  148.  
  149. Code 1: (2)
  150. public class A {
  151. public static void main(String[] args)
  152. {
  153. if (true)
  154. break;
  155. }
  156. }
  157.  
  158. Code 2: (2)
  159. class Test1 {
  160. Test1(int x) {
  161. System.out.println("Constructor called " + x);
  162. }
  163. }
  164.  
  165. class Test2 {
  166. Test1 t1 = new Test1(10);
  167.  
  168. Test2(int i) { t1 = new Test1(i); }
  169.  
  170. public static void main(String[] args) {
  171. Test2 t2 = new Test2(5);
  172. }
  173. }
  174.  
  175. Code 3: (2)
  176. class Test2 {
  177. public static void main(String[] args)
  178. {
  179. int arr[][] = { { 11, 22 }, { 33, 44, 55 } };
  180. for (int i = 0; i < 2; i++) {
  181. for (int j = 0; j < arr.length; j++)
  182. System.out.print(arr[i][j] + " ");
  183. System.out.println();
  184. }
  185. }
  186. }
  187.  
  188. Code 4: (2)
  189. interface A
  190. {
  191. void myMethod();
  192. void getInfo();
  193. }
  194.  
  195. abstract class B implements A
  196. {
  197. void getData()
  198. {
  199. System.out.println("A");
  200. }
  201. }
  202.  
  203. public class Test extends B
  204. {
  205. public void myMethod()
  206. {
  207. System.out.println("D");
  208. }
  209. public void getInfo()
  210. {
  211. System.out.println("B");
  212. }
  213.  
  214. public static void main(String[] args)
  215. {
  216. B obj = new Test();
  217. obj.getInfo();
  218. }
  219. }
  220.  
  221. Code 5:
  222. public static void main(String args[])
  223. {
  224. boolean b[] = new boolean[52];
  225. b[26]=true;
  226. while(!b[b.length/2])
  227. {
  228. System.out.print("***");
  229. }
  230. int x=0;
  231. while (true)
  232. {
  233. if(++x < 5) System.out.print("A");
  234. else break;
  235. }
  236. for(x=b.length/2-2; x<b.length; x++)
  237. {
  238. if(b[x])
  239. {
  240. System.out.print("***");
  241. break;
  242. }
  243. else
  244. System.out.print("B");
  245. }
  246.  
  247. }
Add Comment
Please, Sign In to add comment