1. You have created the following class to print some numbers:
public class PrintNumber {
int a;
int b;
public void basefunt() {
a = 0;
b = 0;
int[] c = { 0 };
modify(b, c);
System.out.println("" + a + b + c[0]);
}
public void modify(int b, int[] c) {
a = 1;
b = 1;
c[0] = 1;
}
public static void main(String args[]) {
PrintNumber p = new PrintNumber();
p.basefunt();
}
}
What will be the output?
Answers:
• 000
• 101
• 001
• 110
• 100
2. Which of the following is incorrect with regard to Exceptions?
Answers:
• Catching
java.lang.Exception will catch any .NET exceptions
• Catching
System.Exception will catch any .NET exceptions
• Catching
java.lang.Exception will catch any java exceptions
• Catching
System.Exception will catch any java exceptions
3. You have defined an Integer as follows:
int IntPageId = 5;
What would you write for changing it into a String data type?
Answers:
• String strPageId
= System.Data.ToString(IntPageId);
• String strPageId
= IntPageId.ToString();
• String strPageId
= System.Convert.ToString(IntPageId);
• String strPageId
= IntPageId;
4. You have defined two classes (as mentioned below) in a java file named "CustomerClass.java" :
class Customer
{
. . .
}
class OldCustomer
{
. . .
}
None of the classes defined above have any static void method. What will happen on compiling the classes on .Net command prompt?
Answers:
• This will give a
compilation error saying 'one class must be declared public'
• This will give a
compilation error saying 'two non-public classes cannot be declared in one java
file'
• This will give a
compilation error saying, 'No main method found'
• None of the
above
5. You want a component to resize vertically, but not horizontally. How should it be placed?
Answers:
• BorderLayout in
the North or South location
• FlowLayout as
the first component
• BorderLayout in
the East or West location
• BorderLayout in
the Center location
• GridLayout
6. Two functions are defined with the same name in a class:
public boolean isGreater(int no1, int no2)
public boolean isGreater(String st1, String st2)
Which of the following concept does this definition represent?
Answers:
• Abstraction
• Overloading
• Overriding
• Encapsulation
7. Which of the following statements is incorrect with regard to data types?
Answers:
• J# wraps
primitive types to Objects behind the scene
• Primitive data
types are defined as structures in the system namespace
• Internal
handling of primitive data types in J# is exactly the same as in java
8. A Student class extends Person class:
1��������class Person
2��������{
3�������� ��������int heightcm;
4
5����������������Person()
6����������������{��������this.heightcm=160; ��������}
7��������
8����������������int getHeight()
9����������������{��������return heightcm;����������}
10
11����������������String display()
12����������������{��������return "Person height is " + heightcm; }
13��������}
14��������class Student extends Person
15��������{
16����������������int studhtcm;
17����������������String className()
18����������������{��������return "Student";��������}
19
20����������������public static void main(String args[])
21����������������{
22������������������������Person obj = new Student();
23������������������������System.out.println(obj.getHeight());
24������������������������System.out.println(obj.display());
25������������������������System.out.println(obj.className());
26����������������}
27��������}
What will happen on compiling and running the code?
Answers:
• The Program will
compile and run successfully.
• The Program will
not compile due to an error in line 23
• The Program will
not compile due to an error in line 24
• The Program will
not compile due to an error in line 25
9. Which of the following statements is incorrect with regard to Java Code?
Answers:
• The java code
can be compiled in Netbean/Eclipse as well as in VisualStudio
• Netbean compiles
java source to Java byte code whereas Visual Studio compiles it to MSIL
• Both Netbean and
Visual Studio produce class files as a result of compilation
• All of the above
10. You created a few classes (as mentioned below) for file manipulation:
public class CopyFile
{ }
class ReadFile
{ }
class WriteFile
{ }
Which of the following is a valid way to name the '.java' file containing the above classes?
Answers:
• ReadFile.java
• WriteFile.java
•
FileManupulation.java
• All of the above
11. What will be the output when the following code is compiled and run?
abstract class Search {
public Search() { }
public abstract void Result();
}
public class SearchMain extends Search {
public SearchMain() { }
public int Result() {
System.out.println("I am Result()");
return 1;
}
public static void main(String str[]) {
new SearchMain().Result();
}
}
Answers:
• The code will
fail to compile
• The code will
compile but fails to run
• The code will
compile and print "I am Result()"
• The code will
compile but does not produce any output
12. You have defined the following methods in one of the java classes:
1 void setId(int newId)
2 private void manageRecord(int RecordNo)
3 protected void delete(int recordNo)
4 boolean isValidRecord(int recordNo)
Which of the following methods is incorrect for a class that extends above class?
Answers:
• public void
setId(int newId)
• void
manageRecord(int RecordNo)
• void delete(int
recordNo)
• protected
boolean isValidRecord(int recordNo)
13. You have compiled a java class named "DirReader.java" using .Net command prompt. Which of the following commands helps you run it from the same window?
Answers:
• >java
DirReader
• >java
DirReader.java
• >vj DirReader
• >DirReader
14. You have written a java class file named "CustomerManager.java." Which of the following commands helps you compile it on .Net Command prompt?
Answers:
• javax
CustomerManager.java
• java
CustomerManager.java
• jsharp
CustomerManager.java
• vjc CustomerManager.java
15. What will be the output of the following program?
public class Prnt
{
public static void main(String args[])
{
System.out.println(11 ^ 2);
}
}
Answers:
• 10
• 9
• 11
• 13
• 121
16. What will be the output when myMethod() is executed?
class MyPoint {
void myMethod() {
int x, y;
x = 5; y = 3;
System.out.print( " ( " + x + ", " + y + " ) " );
switchCoords( x, y );
System.out.print( " ( " + x + ", " + y + " ) " );
}
void switchCoords( int x, int y ) {
int temp;
temp = x;
x = y;
y = temp;
System.out.print( " ( " + x + ", " + y + " ) " );
}
}
Answers:
• (5, 3) (5, 3)
(5, 3)
• (5, 3) (3, 5)
(3, 5)
• (5, 3) (3, 5)
(5, 3)
• No output will
be printed
17. You have a simple java class named "Record":
public class Record
{
protected void readRecord(int newId) throws Exception,IOException{}
protected void insertRec(int recNo) throws FileNotFoundException,IOException{}
protected void deleteRecord(int recordNo) throws EOFException{}
protected boolean isValidRecord(int recordNo) throws Exception{return true;}
}
Which of the following method declarations will not be legitimate for the child class of "Record" class?
Answers:
• protected void
readRecord(int newId) throws IOException
• protected void
insertRec(int recNo) throws Exception
• public void
deleteRecord(int recordNo) throws EOFException
• public boolean
isValidRecord(int recordNo) throws EOFException
18. Which of the following statements is correct with regard to Final and Abstract?
Answers:
• An abstract
class cannot have final methods
• An abstract
class cannot have non abstract methods
• A final class
cannot have abstract methods
• A final class
cannot have final methods
19. Given below is the definition of two classes in "Maruti.java":
public class Automobile
{ Automobile(int i) {} }
class Maruti extends Automobile
{
public Maruti()
{ System.out.println("In Maruti()"); }
public static void main(String str[])
{ new Maruti(); }
}
What will happen when this code is compiled and run?
Answers:
• The code will
compile but throws an exception when it is run
• The code will
compile and does not produce any output when it is run
• The code will
fail to compile
• None of the
above
20. Which of the following classes does not generate action events?
Answers:
• Choice
• MenuItem
• List
• Checkbox
21. Consider the following program:
import java.util.*;
public class ListColl {
public static void main(String str[]) {
List l = new ArrayList();
l.add("1");
l.add("2");
l.add(1,"3");
List l2 = new LinkedList(l);
l.addAll(l2);
System.out.println(l);
}
}
Which of the following sequences will be printed when the above program is run?
Answers:
• [1, 3, 2, 1, 1,
2]
• [1, 3, 1, 1, 3,
2]
• [1, 1, 2, 1, 3,
2]
• [1, 3, 2, 1, 3,
2]
22. What will be returned by the length()method of File class?
Answers:
• The number of
characters in the file
• The number of
bytes in the file
• The number of
lines in the file
• None of the
above
23. You created the 'Msg' class as follows:
class Msg {
Msg() {
String str1 = "Health";
String str2 = "is";
String str3 = "Wealth";
System.out.println(str1.concat(str2));
str1.concat(str2);
System.out.println(str1.concat(str3));
}
public static void main(String str[]) {
new Msg();
}
}
What will happen on compiling and running the code?
Answers:
• This code will
fail to compile because arrayIndexOutOfBound exception is not caught
• It will print
Healthis on the first line followed by HealthWealth on the second line
• It will print
Healthis on the first line followed by HealthisWealth on the second line
• It will print
Healthis on the first line followed by HealthisHealthWealth on the second line
24. A class named MyLoop is defined as follows:
public class MyLoop
{
public static void main(String args[])
{
int counter = 0;
lbl1: for (int i=10; i<0; i--)
{
int j = 0;
lbl2: while (j < 10)
{
if (j > i) break lbl2;
if (i == j)
{
counter++;
continue lbl1;
}
}
counter--;
}
System.out.println(counter);
}
}
What will happen when you try to compile and run the program?
Answers:
• The program will
fail to compile
• The program will
compile and produce no output
• The program will
print 0 as output
• The program will
print 10 as output
25. You have defined a static method to divide two integers:
1��������public static int divide(int a,int b) throws Exception
2��������{
3����������������if(b==0)
4������������������������throw new Exception("Invalid Value for denominator");
5����������������else
6������������������������return (a/b);
7��������}
Which of the following statements is correct?
Answers:
• The method
syntax is correct
• The general
Exception cannot be specified with parameter (line 4)
• In the line 4,
the word 'throw' should be replaced with 'throws'
• A static method
can be throw not as throw Exceptions
26. What will be the output when the following code is compiled and run?
class Equates {
Equates() {
int a,b,c;
a = b = c = 20;
System.out.println(a);
}
public static void main(String str[]) {
new Equates();
}
}
Answers:
• The code will
fail to compile
• 20 is printed
• Nothing is
printed
• True is printed
27. The classes Zen and Matiz are as follows:
class Zen {
int x = 10;
}
class Matiz {
Matiz() {
Zen z1 = new Zen();
Zen z2 = new Zen();
update(z1);
update(z2);
z1 = z2;
update(z1);
update(z2);
}
private void update(Zen z) {
z.x = 20;
System.out.println(z.x);
}
public static void main(String str[]) {
new Matiz();
}
}
What will be the result obtained on compiling and running the Matiz class?
Answers:
• The code will
fail to compile
• 10 10 10 10
• 20 20 20 20
• 10 20 10 20
28. You need to create a class that associates a set of keys with a set of values. Which of these interfaces is most appropriate?
Answers:
• Collection
• Set
• Map
• SortedSet
29. In the following code, val is an Integer variable:
if( val > 4 ) {
System.out.println( "Test A" );
}else if( val > 9 ) {
System.out.println( "Test B" );
}else
System.out.println( "Test C" );
Which of the following values of 'val' will print 'Test C'?
Answers:
• val < 4
• val between 4
and 9
• val > 9
• No values for val
will result in "Test C" being printed
30. Consider the following class:
public class Intro {
static int a;
int b;
public Intro() {
int c;
c = a;
a++;
b += c;
}
public void Intro() {
int c;
c = a;
a++;
b += c;
}
public static void main(String args[]) {
new Intro();
}
}
What will happen on compiling and running this class?
Answers:
• The code will
fail to compile because there are two constructors with the same names and
parameters
• The code will
fail to compile because the constructor is trying to access a static variable
• The code will
compile but gives a runtime error
• The code will
compile and runs successfully
31. Which of the following Classes contains a method to create a directory?
Answers:
• File
• DataOutput
• Directory
• FileDescriptor
• FileOutputStream
32. Which of the following statements is correct with regard to J#?
Answers:
• All the J# data
types are derived from java.lang.Object
• The
java.lang.Object is a superclass of System.Object
• The
java.lang.Object is an alias for System.Object
• The ObjectImpl
package provides functionality for all the methods belonging to
java.lang.Object
33. Consider the following class:
import java.util.*;
public class Coll
{
public static void main(String str[])
{
List l = new ArrayList();
l.add("1");
l.add("2");
l.add(1,"3");
l2 = new LinkedList(l);
l.addAll(l2);
System.out.println(l);
}
}
Which of the following sequences will be printed on running this class?
Answers:
• [1, 3, 2, 1, 1,
2]
• [1, 3, 1, 1, 3,
2]
• [1, 1, 2, 1, 3,
2]
• [1, 3, 2, 1, 3,
2]
34. What will be the output when the following code is compiled and run?
class Num {
Num() {
int k = 1;
int i = ++k + k++ + + k;
System.out.println(i);
}
public static void main(String str[]) {
new Num();
}
}
Answers:
• The code will
fail to compile
• 8 is printed
• 9 is printed
• 7 is printed
35. What is wrong with the following method?
public void manageCalc()
{
try {
compute();
} finally {
release();
} catch (MyException e) {}
}
}
Answers:
• There is no
error in the code
• The block
'finally' should come after the block 'catch'
• An empty catch
block is not allowed
• None of the
above
36. Two classes are defined as follows:
class Category {}
class Document extends Category {}
class Legal extends Document {}
You initialized the class Legal like this:
Legal legl = new Legal();
What is the sequence of call to the given classes?
Answers:
• It calls
Legal(),Document(), and Category()
• It calls
Legal(),Category(), and Document()
• It calls
Category(),Document(), and Legal()
• It calls
Category(),Legal(), and Document()
37. The Tracer and Viewer classes are as follows:
class Tracer {
public static int traceNo = 10;
}
class Viewer {
Viewer() {
Tracer t1 = new Tracer();
Tracer t2 = new Tracer();
update(t1);
update(t2);
}
private void update(Tracer t) {
t.traceNo = t.traceNo + 1;
System.out.println(t.traceNo);
}
public static void main(String str[]) {
new Viewer();
}
}
What will be the result obtained on compiling and running the viewer on .net command prompt?
Answers:
• The code will
fail to compile
• 11 12
• 11 11
• 12 12
38. Consider the following classes:
class Model
{
public int modelNo;
Model(int modelNum)
{ modelNo=modelNum; }
public int getModel()
{ return modelNo; }
}
public class Item extends Model
{
Item() {}
public static void main(String args[])
{ Item i = new Item(); }
}
What will happen on compiling and running the above classes?
Answers:
• The code will
compile and run successfully
• The code will
not compile as the constructor Item (int modelNo) is missing in the Item class
• The code will
not compile as the call super (ModelNumber) is missing in Item()
• The code will
compile but gives runtime error
39. Which of the following statements is incorrect with regard to interfaces?
Answers:
• A class can
implement multiple interfaces
• An abstract
class cannot extend multiple interfaces
• An interface can
extend multiple interfaces
• Methods with
same name, arguments, and sequence can exist in the interfaces implemented by a
class
40. Which of the following methods will cause a thread to stop?
Answers:
• Calling
interrupt() method of the thread
• Calling sleep()
method on thread
• Conclusion of
execution of the run() method
• None of the
above
41. Which of the following is correct with regard to Net J#?
Answers:
• It supports sun
java up to JDK 1.1.5
• It supports sun
java up to JDK 1.1.4
• It supports sun
java up to JDK 1.1.3
• It supports sun
java enterprise edition and standard edition
42. For a J# project in Visual Studio .Net, the files can be a mixture of .jsl or .java extensions.
Answers:
• True
• False
43. Which of the following is not a correct way of getting 'sin' value?
Answers:
• Math m = null;
double val = m.sin(25);
• double val =
Math.sin(25);
• Math m = new
Math(); double val = m.sin(25);
44. Which of the following visibility modes is not defined in J#?
Answers:
• protected
• private
• package
• default
45. Visual J# runs on .Net framework.
Answers:
• True
• False
46. Which of the following helps you get a double value from a String object named "StrValue?"
Answers:
•
(System.Double)(System.GetDouble(StrValue))
•
(System.Double)(System.ParseDouble(StrValue))
•
(System.Double)(System.Double.Parse(StrValue))
• System.Double.Parse(StrValue)
47. What will be written to the standard output when the following program is run?
public class Message
{
public static void main(String args[])
{
String msg = "GoodDay";
System.out.println(msg.substring(3, 4));
}
}
Answers:
• o
• odD
• d
• dDay
48. How is applet loading speed increased with J# 1.1?
Answers:
• By using a
special algorithm to increase the download speed
• By using CAB
files to download the applet
• By using ZIP
files to reduce the size for download
• All of the above
49. Which of the following are supported by J#?
Answers:
• Windows Forms
• ASP.NET Web
Forms and Mobile Web Forms
• XML Web services
• Cross-language
integration
• All of the above
No comments:
Post a Comment