Java Assignment
Java Assignment
Java Assignment
SAP - Assignment 1
1. Statement.executeUpdate(); method is used for fetching the data from the database from
netbeans?
a. True
b. False
2. Which of the following needs to be imported for java jdbc connectivity JFrame project from
netbeans?
a. Javax.sql.*;
b. Java.sql.*;
c. Javac.sql.*;
d. Java.sql;
3. Which of the following is FALSE about arrays on Java
a. A java array is always an object
b. Length of array can be changed after creation of array
c. Arrays in Java are always allocated on heap
4. You want to take the input of Hobbies from the user, ie Sports, Movies , Traveling etc which of
the following controls would be the most suitable?
a. Radio Button
b. Check Box
c. Text Field
d. Combo box
5. Predict the output?
public class Main {
public static void main(String args[]) {
int arr[] = {10, 20, 30, 40, 50};
for(int i=0; i < arr.length; i++)
{
System.out.print(" " + arr[i]);
}
}
}
a. 10 20 30 40 50
b. Compiler Error
c. 10 20 30 40
6. Which keyword is used for implementing inheritance in java?
a. Implements
b. Extends
c. Inherits
d. Derives
7. Combination of two or more different kinds of inheritances is called?
a. Combination Inheritance
b. Hybrid Inheritance
c. Hierarchical Inheritance
d. Multiple Inheritance
8. Java is object oriented language because it supports classes and encapsulation?
a. True
b. False
9. The overloaded methods are distinguished by both the return type and signature of the
method?
a. True
b. False
10. Arrange the events in the order they need to be carried out 1. Extract data from result set 2.
import the sql package 3. Execute Query 4. Open a connection
a. 1,3,2,4
b. 4,3,2,1
c. 3,2,4,1
d. 2,4,3,1
11. The MySql service is available by default at which of the following ports?
a. 6303
b. 3606
c. 3303
d. 3306
12. Super keyword is used for which of the two purposes?
a. Refer to base class members with same name as in derived class in the derived class
b. Calling the base class destructors
c. To create new objects of the base class
d. Passing parameters to base class constructor
13. Which is not a data type
a. Integer
b. String
c. Variable
d. Boolean
e. Character
14. A constant is declared by using the keyword
a. Int
b. Double
c. MAX
d. Final
15. Object-Oriented Programming means ...
a. Being objective about what you develop
b. Designing the application based on the objects discovered when analysing the problem
c. Writing an algorithm before writing your program and having a test plan
d. Writing a program composed of Java classes
16. Which one is not correct?
a. A class needs to be instantiated as an object before being used
b. An objects exists in memory in run time
c. Class and object are just different names for the same thing
17. Class B inherits from Class A, what cannot be said:
a. B is a sub-class of A
b. A is a super-class of B
c. B has access to private members of A
d. B has access to protected members of A
18. Which one needs a web page to run
a. A Java Application
b. A Java Stand-Alone Application
c. A Java Applet
d. A Java Class
19. An array holds:
a. Similar values of same data type
b. Different values of same data type
c. Same values of different data types
d. Different values of different data types
20. The following prototype shows that a Cylinder subclass is derived from a superclass called Circle
a. Class Circle extends Cylinder
b. Class Cylinder derived Circle
c. Class Cylinder extends Circle
d. Class Circle derived Cylinder
21. With inheritance, a derived subclass object can directly access any
a. Public or private superclass member
b. Private superclass member
c. Public superclass member (and protected subclass members if it's in the same package)
d. Protected, public or private superclass member
22. Following code will result in: int num = 8/0;
a. Compilation error: Divisions must be in a try block
b. Compilation error: DivideByZeroException
c. Runtime Exception
d. No Error: a is NaN
23. If class A implements an interface does it need to implement all methods of that interface?
a. Yes, always.
b. No, not when A is abstract
24. The methods wait(), notify() and notifyAll() in Object need to be called from synchronized pieces
of code.
a. True
b. False
25. The default statement of a switch is always executed.
a. True
b. False
26. Output of following Java program?
class Main {
public static void main(String args[]) {
System.out.println(fun());
}
int fun()
{
return 20;
}
}
a. 20
b. Compile error
c. 0
d. garbage value
27. What will be the value of “num” after the following statements? int num; num = (5+4); num =
num / 9; num = 9;
a. 9
b. 1
c. 0
d. Num
28. If you want your conditional to depend on two conditions BOTH being true, what is the proper
notation to put between the two Boolean statements ?
a. &
b. &&
c. |
d. ||
29. Predict the output
class Main {
public static void main(String args[]) {
int t;
System.out.println(t);
}
}
a. 0
b. garbage value
c. compiler error
d. runtime error
30. Which of the following means that in order for the conditional to happen, either x must be less
than 3 or y must be greater than or equal to 4 ?
a. If ((x < 3) && (y > 4))
b. If (x < 3 y >= 4)
c. If ((x < 3) || (y > = 4))
d. If ((x > 3) || (y < = 4))
31. What is the Message displayed in the applet made by this program?
import java.awt.*;
import java.applet.*;
public class myapplet extends Applet {
public void paint(Graphics g) {
g.drawString("A Simple Applet", 20, 20);
}
}
a. A Simple Applet
b. A Simple Applet 20 20
c. Compilation Error
d. Runtime Error
32. A Java application
a. May involve one or more classes.
b. Can be run on different platforms, not just on the one it was written on.
c. Both the above are true.
33. What will be the output of the following program?
class Test {
public static void main(String[] args)
{
int i = 0, j = 9;
do {
i++;
if (j-- < i++) {
break;
}
} while (i < 5);
System.out.println(i + "" + j);
}
}
a. 44
b. 55
c. 66
d. 77
34. What will be the output of the following program?
class Test {
static String s = "";
public static void main(String[] args)
{
P:
for (int i = 2; i < 7; i++) {
if (i == 3)
continue;
if (i == 5)
break P;
s = s + i;
}
System.out.println(s);
}
}
a. 32
b. 23
c. 24
d. 42
35. It is the process of removing errors found in the program.
a. Editing
b. Debugging
c. Compiling
d. Running
36. Predict the output of following Java program.
class Test {
public static void main(String[] args) {
for(int i = 0; 0; i++)
{
System.out.println("Hello");
break;
}
}
}
a. Hello
b. Empty Output
c. Compiler error
d. Runtime error
37. Which of these operators can be used to concatenate two or more String objects?
a. +
b. +=
c. &
d. ||
38. Which of these methods can be used to output a sting in an applet?
a. display()
b. print()
c. drawString()
d. transient()
39. Which of the following is true about inheritance in Java?
1) Private methods are final.
2) Protected members are accessible within a package and inherited classes outside the
package.
3) Protected methods are final.
4) We cannot override private methods.
a. 1, 2 and 4
b. Only 1 and 2
c. 1, 2 and 3
d. 2, 3 and 4
40. Predict the output
class Test {
public static void main(String args[]) {
int arr[2];
System.out.println(arr[0]);
System.out.println(arr[1]);
}
}
a. 0
0
b. garbage value
garbage value
c. Compiler Error
d. Exception
Part II