Q1. What is the meaning of the return data type void?
A. An empty memory space is returned so that the developers can utilize it.
B. void returns no data type.
C. void is not supported in Java
D. None of the above
Q2. A lower precision can be assigned to a higher precision value in Java. For example a byte type data can
be assigned to int type.
A. True B. False
Q3. Which of the following statements about the Java language is true?
A. Both procedural and OOP are supported in Java.
B. Java supports only procedural approach towards programming.
C. Java supports only OOP approach.
D. None of the above.
Q4. Which of the following statements is false about objects?
A. An instance of a class is an object
B. Objects can access both static and instance data
C. Object is the super class of all other classes
D. Objects do not permit encapsulation
Q5. Which methods can access to private attributes of a class?
A. Only Static methods of the same class
B. Only instances of the same class
C. Only methods those defined in the same class
D. Only classes available in the same package.
Q6. What is an aggregate object?
A. An object with only primitive attributes
B. An instance of a class which has only static methods
C. An instance which has other objects
D. None of the above
Q7. Assume that File is an abstract class and has toFile() method. ImageFile and BinaryFile are concrete
classes of the abstract class File.
Also, assume that the method toFile() is implemented in both BinaryFile and ImageFile. A File references
an ImageFile object in memory and the toFile() method is called, which implementation method will be
called?
A. Binary File B. Image File C. Both File and Binary Files D. None of the above
Q8. A class can have many methods with the same name as long as the number of parameters or type of
parameters is different. This OOP concept is known as
A. Method Invocating B. Method Overriding
C. Method Labeling D. Method Overloading
Q9. Which of the following is considered as a blue print that defines the variables and methods common to
all of its objects of a specific kind?
A. Object B. Class C. Method D. Real data types
Q10. Given:
public static void main(String[] args) {
String str = "null";
if (str == null) {
System.out.println ("null");
} else (str.length() == 0) {
System.out.println("zero");
} else {
System.out.println ("some");
}
}
What is the result?
A. null B. zero C. some D. Compilation fails.
E. An exception is thrown at runtime.
Q11. After the following code fragment, what is the value in fname?
String str;
Int fname;
str = "Foolish boy.";
fname = str.indexOf("fool");
A. 0 B. 1 C. -1 D. 2
Q12. What is the value of ‘number’ after the following code fragment execution?
int number = 0;
int number2 = 12
while (number < number2){
number = number + 1;
}
A. 5 B. 12 C. 21 D. 13
Q13. Given the following code snippet;
int salaries[];
int index = 0;
salaries = new int salaries[4];
while (index < 4){
salaries[index] = 10000;
index++;
}
What is the value of salaries [3]?
A. 40000 B. 50000 C. 15000 D. 10000
Q14. Which of the following is not a return type?
A. boolean B. void C. public D. Button
Q15. class Main
{
public static void main( String args[] )
{
String mesg = "Answer is ";
int sum = 1 + 2;
System.out.println( mesg + sum );
}
}
What is the effect of executing the class Main above?
(a) Prints 3 (b) Prints Answer is 3 (c) Prints Answer is 1 + 2 (d) Prints mesg + sum
Q16. class Main
{
public static void main( String args[] )
{
int this_number = 3;
int that_number;
while ( this_number < 10)
{
that_number = this_number;
this_number = this_number + that_number / 2;
}
System.out.println( "Answer is " + this_number );
}
}
What is the effect of executing the class Main above?
(a) Prints Answer is 12 (c) Prints Answer is 14
(b) Prints Answer is 13 (d) Prints Answer is 15
(e) Infinite Loop(no o/p)
Q17. A class method call
(a) Requires that the class identifier precedes the method identifier.
(b) May be called with the method identifier only in certain circumstances.
(c) Is only possible after a new object is constructed.
(d) Uses the class identifier only for readability.
Q18. What is the output of the following program?
public class Q3{
public static void main(String args [ ]){
method1();
method3();
method2();
}
public static void method1(){
System.out.println("Calling method 1");
}
public static void method2(){
System.out.println("Calling method 3");
}
public static void method3(){
System.out.println("Calling method 2");
}
}
(A) Calling method 1 (B) Calling method 1 (C) method 1 (D) Error message
Calling method 2 Calling method 3 method 3
Calling method 3 Calling method 2 method 2
Q19. Object methods are typically used when
(a) Only a single copy of the class needs to be loaded
(b) Multiple copies or instances of a class are required.
(c) It is not necessary to pass information to the methods.
(d) Only return methods are used in a class.
Q20. When is a constructor called?
(A) Each time the constructor identifier is used in a program statement
(B) During the instantiation of a new object
(C) During the construction of a new class
(D) At the beginning of any program execution
Q21. Instantiation is the moment that
(A) Memory is allocated for a specific object of a class.
(B) Memory is allocated for a specific object, which is a member of a class.
(C) A program is ready for execution.
(D) A program compiles correctly.
Q22. Given:
class Foo{
static void alpha() { /* more code here */ }
void beta() { /* more code here */ }
}
Which two statements are true? (Choose two.)
A. Foo.beta() is a valid invocation of beta().
B. Foo.alpha() is a valid invocation of alpha().
C. Method beta() can directly call method alpha().
D. Method alpha() can directly call method beta().
Q23. Given:
public class Yippee2 {
static public void main(String [] yahoo) {
for(int x = 1; x < yahoo.length; x++) {
System.out.print(yahoo[x] + " ");
}
}
}
and the command line invocation: java Yippee2 a b c
What is the result?
A. a b B. b c C. a b c D. Compilation fails. E. Runtime Exception
Q24. Given:
public class Yippee {
public static void main(String [] args) {
for(int x = 1; x < args.length; x++) {
System.out.print(args[x] + " ");
}
}
}
and two separate command line invocations: java Yippee
java Yippee 1 2 3 4
What is the result?
A. No output is produced.
1 2 3
B. No output is produced.
2 3 4
C. No output is produced.
1 2 3 4
D. An exception is thrown at runtime.
1 2 3
E. An exception is thrown at runtime.
2 3 4
F. An exception is thrown at runtime.
1 2 3 4
Q25. Which are valid declarations? (Choose all that apply.)
A. int $x; B. int 123; C. int _123; D. int #dim;
E. int %percent; F. int *divide; G. int central_sales_region_Summer_2005_gross_sales;
Q26. Which two code fragments correctly create and initialize a static array of int elements? (Choose two.)
A. static final int[] a = { 100,200 };
B. static final int[] a;
static { a=new int[2]; a[0]=100; a[1]=200; }
C. static final int[] a = new int[2]{ 100,200 };
D. static final int[] a;
static void init() { a = new int[3]; a[0]=100; a[1]=200; }
Q27. A programmer needs to create a logging method that can accept an arbitrary number of arguments. For
example, it may be called in these ways:
logIt("log message1");
logIt("log message2","log message3");
logIt("log message4","log message5","log message6");
Which declaration satisfies this requirement?
A. public void logIt(String * msgs)
B. public void logIt(String [] msgs)
C. public void logIt(String... msgs)
D. public void logIt(String msg1, String msg2, String msg3)
Q28. Given: 35 String #name = "Jane Doe";
36 int $age = 24;
37 Double _height = 123.5;
38 double ~temp = 37.5;
Which two statements are true? (Choose two.)
A. Line 35 will not compile.
B. Line 36 will not compile.
C. Line 37 will not compile.
D. Line 38 will not compile.
Q29. Given:
public class Test
{
public static void main(String [] args) {
int x = 5;
boolean b1 = true;
boolean b2 = false;
if ((x == 4) && !b2 )
System.out.print("1 ");
System.out.print("2 ");
if ((b2 = true) && b1 )
System.out.print("3 ");
}
}
What is the result?
A. 2 B. 3 C. 1 2 D. 2 3 E. 1 2 3
F. Compilation fails. G. An exception is thrown at runtime.
Q30. Given:
class Hexy {
public static void main(String[] args) {
Integer i = 42;
String s = (i<40)?"life":(i>50)?"universe":"everything";
System.out.println(s);
}
}
What is the result?
A. null B. life C. universe D. everything
E. Compilation fails. F. An exception is thrown at runtime.
1.b
2.a
3.c
4.d
5.c
6.c
7.b
8.d
9.b
10.d
11.c(if not matching to string gives -1)
12.b
13.d
14.c
15.b
16.b
17.a
18.a
19.b
20.b
21.a
22.b
23.b
24.b
25.a,c,g
26.a,b
27.c
28.a,d
29.d
30d
3 comments:
what about the answers?
I want answers.
Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
Selenium Training in Chennai Tamil Nadu | Selenium Training Institute in Chennai anna nagar | selenium training in chennai velachery
Selenium Training in Bangalore with placements | Best Selenium Training in Bangalore marathahalli
java training in chennai | java training in chennai Velachery |java training in chennai anna nagar
Inspiring writings and I greatly admired what you have to say , I hope you continue to provide new ideas for us all and greetings success always for you..Keep update more information..
Data Science course in Indira nagar
Data Science course in marathahalli
Data Science Interview questions and answers
Data science training in tambaram
Data Science course in btm layout
Data science course in kalyan nagar
Post a Comment