Upwork Test Answers Java-Script Skill Test
Question: 01
What is the java.net.IDN class in 1.6?
a. Methods to resolve integrated domain names (IDNs), such domain names are special embedded names
b. Methods to swap bytes between network byte order and host byte order
c. Methods to convert internationalized domain names (IDNs) between a normal Unicode representation and an ASCII Compatible Encoding (ACE) representation
d. This class does not exist
e. None of the above
Answer: c. Methods to convert internationalized domain names (IDNs) between a normal Unicode representation and an ASCII Compatible Encoding (ACE) representation
Question: 02
What will be the output of the following program?public class Test
{
public static void main (String args[]) throws Exception
{
Test o = new Test ();
System.out.println (o.content ());
}public String content () throws Exception
{throw new Exception ("This is an exception on this.content ()");
}private static class B
{public String content ()
{return ''B'';
}
}private static class A extends B
{public String content ()
{return ''A'';
}
}
}
a. The code will fail to compile
b. The code will compile but throw an exception at runtime
c. The code will compile and on running, it will print ''A''
d. The code will compile and on running, it will print ''B''
Answer: The code will compile but throw an exception at runtime
Question: 03
Which of these interfaces are used by implementations of models for JTable?
a. TableModel
b. TableColumnModel
c. TableSelectionModel
d. ListModel
Answer: a. TableModel
b. TableColumnModel
Question: 04
How many times can classes be nested within a class?
a. 5
b. 8
c. 4
d. Any number of times
Answer: d. Any number of times
Question: 05
One method in your application needs to be synchronized. Which of the following options are correct for synchronization?
a. public synchronized void Process(void){}
b. public void Process(){ synchronized(this){ } }
c. public void synchronized Process(){}
d. public synchronized void Process(){}
Answer: b. public void Process(){ synchronized(this){ } }
c. public void synchronized Process(){}
Question: 06
What could be the replacement of "//ABC" in the following code?public class Jam?
{
public void apple(int i, String s)
{}
//ABC
}
a. public void apple(String s, int i){}
b. public int apple(int i, String s){}
c. public void apple(int i, String mystring){}
d. public void Apple(int i, String s) {}
Answer: a. public void apple(String s, int i){}
d. public void Apple(int i, String s) {}
Question: 07
What will be the output when the following code is compiled and run?public class Test
{
public static void main (String args[])
{
int i;
i = 3;
System.out.println ((int)i * 2.5 / 3.0);
}
}
a. The code will compile, but it will throw an exception when it is run
b. The code will compile and it will not produce any output when it is run
c. The code will fail to compile
d. The code will print 3
e. The code will print 2.5
f. The code will print 2
Answer: e. The code will print 2.5
Question: 08
What would happen on trying to compile and run the following code?public class MainCls
{
public static void main(String argv)
{
System.out.println("My Text");
}
}
a. A compile error will be generated because 'main' is a reserved word and cannot be used for a class
b. "My Text" will be displayed
c. The code will compile. A runtime error will occur because 'main' is not properly defined
d The code will compile. A runtime error will occur because constructor is not defined
Answer: c. The code will compile. A runtime error will occur because 'main' is not properly defined
Question: 09
What will be the output when this code is compiled and run?public class Test?
{
static int x = 10;
public Test ()
{
Bar b = new Bar ();
Bar b1 = new Bar ();
update (b);
update (b1);
}private void update (Bar bar)
{
bar.x = ++x;
System.out.println (bar.x);
}public static void main (String args[])
{
File f = new File("/","autoexec.bat"); b.DataInputStream d = new DataInputStream(System.in);c.RandomAccessFile r = new RandomAccessFile("OutFile"); d.OutputStreamWriter o = newOutputStreamWriter(System.out);
}private class Bar
{public int x = 10;
}
}
a. The code will fail to compile
b. 11 12
c. 11 11
d. 12 12
Answer: b. 11 12
Question: 10
Which of the following statement will not compile?
a. File f = new File("/","autoexec.bat");
b. DataInputStream d = new DataInputStream(System.in);
c. RandomAccessFile r = new RandomAccessFile("OutFile");
d. OutputStreamWriter o = new OutputStreamWriter(System.out);
Answer: c. RandomAccessFile r = new RandomAccessFile("OutFile");
Question: 11
Which of the following are "keywords" in Java?
a. default
b. NULL
c. String
d. throws
Answer: d. throws
Question: 12
Which of the following statements is true of the HashMap class?
a. It stores information as key/value pairs
b. Elements are returned in the order they were added
c. It does not permit null keys
d. It does not permit null values
Answer: a. It stores information as key/value pairs
Question: 13
How does the set collection deal with duplicate elements?
a. Duplicate values will cause an error at compile time
b. A set may contain elements that return duplicate values from a call to the equals method
c. An exception is thrown if you attempt to add an element with a duplicate value
d. The add method returns false if you attempt to add an element with a duplicate value
Answer: d. The add method returns false if you attempt to add an element with a duplicate value
Question: 14
What is wrong with the following code?class X extends Exception {}
public class Y
{public void foo()
{
try {
b();
}
finally {
ba();
}
catch (MyException e) {}
}
public void b() throws X {
throw new X();
}public void ba() throws RuntimeException {
throw new RuntimeException();
}
}
a. Nothing is wrong with the code
b. Finally block should come after the catch block
c. An empty catch block is not allowed
d. None of the above
Answer: d. None of the above
Question: 15
Is the following code valid?InetAddress ad = InetAddress.getByName ("195.186.2.111"); ?
a. Yes
b. No
Answer: a. Yes
Question: 16
What will be the output of this program?public class Test?
{
public static void main (String args[])
{
String a, b, c, d;
a = ''Hello1234'';
b = ''Hello'' + String.valueOf(1234);
c = ''Hello'' + ''1234'';
d = new String (new char[]{'H', 'e', 'l', 'l', 'o', '1', '2', '3', '4'});
System.out.print (a == b);
System.out.print ('' '');
System.out.print (a.equals(b));
System.out.print ('' '');
System.out.print (a == c);
System.out.print ('' '');
System.out.print (a.equals(c));
System.out.print ('' '');
System.out.print (a == d);
System.out.print ('' '');
System.out.print (a.equals(d));
System.out.print ('' '');
}
}
a. true truetruetrue false true
b. false true truetrue false false
c. false true truetrue false true
d. false false true true false true
Answer: ----
Question: 17
Which of the following cannot apply to constructors?
a. Name same as class name
b. Void return type
c. Can have parameters
d. Overloading
Answer: b. Void return type
Question: 18
Choose the correct declarations for the main() method which will allow the class to be run as a standalone program.
a. public void main(String str[])
b. static public void main(String str[])
c. public static int main(String str[])
d. public static void main(String str[])
Answer: d. public static void main(String str[])
Question: 19
For a class defined inside a method, what rule governs access to the variables of the enclosing method?
a. The class can only access transient variables
b. The class can only access static variables
c. The class can only access final variables
d. The class can access any variable
Answer: a. The class can only access transient variables
Question: 20
A method can be defined as native to:
a. Overcome the limitation of the private scope of a method
b. Get to access hardware that Java does not know about
c. Write optimized code for performance in a language such as C/C++
d. Define a new data type such as an unsigned integer
Answer: b. Get to access hardware that Java does not know about
c. Write optimized code for performance in a language such as C/C++
Question: 21
What will be the output of the following line?System.out.println(Math.floor(-2.1)); ?
a. -2
b. 2.0
c. -3
d. -3.0
Answer: d. -3.0
Question: 22
For the given variables, which of the following will compile without an error?char c = 'c';
int i = 50;
double d = 80;
long l = 200;
String s = "Goodbye";
a. s+=i;
b. i+=s;
c. c+=s;
d. c=c+i;
Answer: s+=i;
What is the java.net.IDN class in 1.6?
a. Methods to resolve integrated domain names (IDNs), such domain names are special embedded names
b. Methods to swap bytes between network byte order and host byte order
c. Methods to convert internationalized domain names (IDNs) between a normal Unicode representation and an ASCII Compatible Encoding (ACE) representation
d. This class does not exist
e. None of the above
Answer: c. Methods to convert internationalized domain names (IDNs) between a normal Unicode representation and an ASCII Compatible Encoding (ACE) representation
Question: 02
What will be the output of the following program?public class Test
{
public static void main (String args[]) throws Exception
{
Test o = new Test ();
System.out.println (o.content ());
}public String content () throws Exception
{throw new Exception ("This is an exception on this.content ()");
}private static class B
{public String content ()
{return ''B'';
}
}private static class A extends B
{public String content ()
{return ''A'';
}
}
}
a. The code will fail to compile
b. The code will compile but throw an exception at runtime
c. The code will compile and on running, it will print ''A''
d. The code will compile and on running, it will print ''B''
Answer: The code will compile but throw an exception at runtime
Question: 03
Which of these interfaces are used by implementations of models for JTable?
a. TableModel
b. TableColumnModel
c. TableSelectionModel
d. ListModel
Answer: a. TableModel
b. TableColumnModel
Question: 04
How many times can classes be nested within a class?
a. 5
b. 8
c. 4
d. Any number of times
Answer: d. Any number of times
Question: 05
One method in your application needs to be synchronized. Which of the following options are correct for synchronization?
a. public synchronized void Process(void){}
b. public void Process(){ synchronized(this){ } }
c. public void synchronized Process(){}
d. public synchronized void Process(){}
Answer: b. public void Process(){ synchronized(this){ } }
c. public void synchronized Process(){}
Question: 06
What could be the replacement of "//ABC" in the following code?public class Jam?
{
public void apple(int i, String s)
{}
//ABC
}
a. public void apple(String s, int i){}
b. public int apple(int i, String s){}
c. public void apple(int i, String mystring){}
d. public void Apple(int i, String s) {}
Answer: a. public void apple(String s, int i){}
d. public void Apple(int i, String s) {}
Question: 07
What will be the output when the following code is compiled and run?public class Test
{
public static void main (String args[])
{
int i;
i = 3;
System.out.println ((int)i * 2.5 / 3.0);
}
}
a. The code will compile, but it will throw an exception when it is run
b. The code will compile and it will not produce any output when it is run
c. The code will fail to compile
d. The code will print 3
e. The code will print 2.5
f. The code will print 2
Answer: e. The code will print 2.5
Question: 08
What would happen on trying to compile and run the following code?public class MainCls
{
public static void main(String argv)
{
System.out.println("My Text");
}
}
a. A compile error will be generated because 'main' is a reserved word and cannot be used for a class
b. "My Text" will be displayed
c. The code will compile. A runtime error will occur because 'main' is not properly defined
d The code will compile. A runtime error will occur because constructor is not defined
Answer: c. The code will compile. A runtime error will occur because 'main' is not properly defined
Question: 09
What will be the output when this code is compiled and run?public class Test?
{
static int x = 10;
public Test ()
{
Bar b = new Bar ();
Bar b1 = new Bar ();
update (b);
update (b1);
}private void update (Bar bar)
{
bar.x = ++x;
System.out.println (bar.x);
}public static void main (String args[])
{
File f = new File("/","autoexec.bat"); b.DataInputStream d = new DataInputStream(System.in);c.RandomAccessFile r = new RandomAccessFile("OutFile"); d.OutputStreamWriter o = newOutputStreamWriter(System.out);
}private class Bar
{public int x = 10;
}
}
a. The code will fail to compile
b. 11 12
c. 11 11
d. 12 12
Answer: b. 11 12
Question: 10
Which of the following statement will not compile?
a. File f = new File("/","autoexec.bat");
b. DataInputStream d = new DataInputStream(System.in);
c. RandomAccessFile r = new RandomAccessFile("OutFile");
d. OutputStreamWriter o = new OutputStreamWriter(System.out);
Answer: c. RandomAccessFile r = new RandomAccessFile("OutFile");
Question: 11
Which of the following are "keywords" in Java?
a. default
b. NULL
c. String
d. throws
Answer: d. throws
Question: 12
Which of the following statements is true of the HashMap class?
a. It stores information as key/value pairs
b. Elements are returned in the order they were added
c. It does not permit null keys
d. It does not permit null values
Answer: a. It stores information as key/value pairs
Question: 13
How does the set collection deal with duplicate elements?
a. Duplicate values will cause an error at compile time
b. A set may contain elements that return duplicate values from a call to the equals method
c. An exception is thrown if you attempt to add an element with a duplicate value
d. The add method returns false if you attempt to add an element with a duplicate value
Answer: d. The add method returns false if you attempt to add an element with a duplicate value
Question: 14
What is wrong with the following code?class X extends Exception {}
public class Y
{public void foo()
{
try {
b();
}
finally {
ba();
}
catch (MyException e) {}
}
public void b() throws X {
throw new X();
}public void ba() throws RuntimeException {
throw new RuntimeException();
}
}
a. Nothing is wrong with the code
b. Finally block should come after the catch block
c. An empty catch block is not allowed
d. None of the above
Answer: d. None of the above
Question: 15
Is the following code valid?InetAddress ad = InetAddress.getByName ("195.186.2.111"); ?
a. Yes
b. No
Answer: a. Yes
Question: 16
What will be the output of this program?public class Test?
{
public static void main (String args[])
{
String a, b, c, d;
a = ''Hello1234'';
b = ''Hello'' + String.valueOf(1234);
c = ''Hello'' + ''1234'';
d = new String (new char[]{'H', 'e', 'l', 'l', 'o', '1', '2', '3', '4'});
System.out.print (a == b);
System.out.print ('' '');
System.out.print (a.equals(b));
System.out.print ('' '');
System.out.print (a == c);
System.out.print ('' '');
System.out.print (a.equals(c));
System.out.print ('' '');
System.out.print (a == d);
System.out.print ('' '');
System.out.print (a.equals(d));
System.out.print ('' '');
}
}
a. true truetruetrue false true
b. false true truetrue false false
c. false true truetrue false true
d. false false true true false true
Answer: ----
Question: 17
Which of the following cannot apply to constructors?
a. Name same as class name
b. Void return type
c. Can have parameters
d. Overloading
Answer: b. Void return type
Question: 18
Choose the correct declarations for the main() method which will allow the class to be run as a standalone program.
a. public void main(String str[])
b. static public void main(String str[])
c. public static int main(String str[])
d. public static void main(String str[])
Answer: d. public static void main(String str[])
Question: 19
For a class defined inside a method, what rule governs access to the variables of the enclosing method?
a. The class can only access transient variables
b. The class can only access static variables
c. The class can only access final variables
d. The class can access any variable
Answer: a. The class can only access transient variables
Question: 20
A method can be defined as native to:
a. Overcome the limitation of the private scope of a method
b. Get to access hardware that Java does not know about
c. Write optimized code for performance in a language such as C/C++
d. Define a new data type such as an unsigned integer
Answer: b. Get to access hardware that Java does not know about
c. Write optimized code for performance in a language such as C/C++
Question: 21
What will be the output of the following line?System.out.println(Math.floor(-2.1)); ?
a. -2
b. 2.0
c. -3
d. -3.0
Answer: d. -3.0
Question: 22
For the given variables, which of the following will compile without an error?char c = 'c';
int i = 50;
double d = 80;
long l = 200;
String s = "Goodbye";
a. s+=i;
b. i+=s;
c. c+=s;
d. c=c+i;
Answer: s+=i;
Don't Miss A Single Updates
✓Remember to check your email account to confirm your subscription.