Java Upwork Test

0
553

We don’t guarantee that all provided answers are correct.

Which statement is true about the given code?
public class Test78 {
public static void main(String[] args) throws Exception
{
new JBean(). setHeight(1).setWidht(2).setDepth(3).setDensity(9);
}
}
class JBean {
private int height, width, depth, density;
public JBean setHeight (int h) { this.height = h; return this;}
public JBean setWidht (int w) { this.widht = w; return this; }
public JBean setDepth (int d) { this. depth = d; return this;}
public JBean setDensity (int d) { this.density = d; return this; }
}
Answer

  • The code does not compile, because two setters have a formal parameter with the same name
  • The setters of the JBean class are JavaBean-compliant
  • The code complies, but throws a NullpointerException at run-time
  • The code compiles and runs

What is the purpose java.exe?
Answer

  • Execute compiled bytecode on jvm
  • Compile .java files into bytecode
  • Compile .java files and run them

Which of the following is the correct way in java to show that the class Developer inherits from the parent class freelance?
Answer

  • public class Developer : Freelancer {
    // methods and variables defined here
    }
  • public class Developer (Freelancer) {
    // methods and variables defined here!
    }
  • public class Developer extends Freelancer {
    // methods and variables defined here
    }
  • public abstract class Developer (Freelancer) {
    // methods and variables defined here
    }

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);
}
}
Answer

  • The code will compile, but it will throw an exception when it run
  • The code will compile and it will not produce any output when it is run
  • The code will fall to compile
  • The code will print 3
  • The code will print 2.5
  • The code will print 2

Which of these is not an event listener adapter defined in the java.awt.event package?
Answer

  • ActionAdapter
  • Mouselistener
  • Windowadapter
  • Focouslistener

How many object are created by the following code?
object a, b, c, d, e;
e = new object ();
b = a =e;
e = new object ();
Answer

  • 2
  • 5
  • 4
  • That code is invalid

Given the following class , which of the following is true?(choose all that apply)
1:public class Upwork {
2:
3: public void freelancer(boolean time) {
4:
5: if (time) {
6:
7: }
8: System .out.printfln(result);
9:
10 }
11: }
NOTE: There may be more than one right answer.
Answer

  • If String result =”job”; is inserted on line 2, the code will compile
  • If String result = “job”; is inserted on line 4, the code will compile
  • If String result =”job”; is inserted on line 6 the code will compile
  • If String result =”job”; is inserted on line 9 the code will compile
  • None of the above changes will make the code compile

Which interface does java.util.Hashtable implement?
Answer

  • Java.util.Map
  • Java.util.List
  • Java.util.Hashtable
  • Java.util.Collection

Consider below code:
class Ex1{
public static void main(string args[]){
int x= 10;
int y = new Ex1().change(x);
system.out.print(x+y);
}
int change(int x){
x = 12;
return x;
}
}
What will be output?
Answer

  • 20
  • 22
  • Compilation fails
  • 24
  • An exception is thrown at runtime

What will be the output of the following code:
for(int i=1; i<10;i++)
{
system.out.print(” “+i);
}
Answer

  • 1 2 3 4 5 6 7 8 9 10
  • 0 1 2 3 4 5 6 7 8 9
  • 1 2 3 4 5 6 7 8 9

Which of the following is used to find out that a thread is still running?
Answer

  • run()
  • Alive()
  • isAlive()
  • checkcRun()

Which of the following is the best way to compare the values stored in two objects?
Answer

  • Using two equel signs eg.–
  • Overriding equels() Method
  • Overridding toString() method
  • Overridding clone() method

What will be the output, if the following program is run?
public class Test8 {
public static void main(String[] args)
{
System.out.println(Math.sqrt(-4));
}
}
Answer

  • null
  • 2
  • NaN
  • -2.0

Which collection class allows you to associate its elements with key values, and allows you to retrieve objects in FIFO(first-in-first-out) sequence?
Answer

  • java.util.ArrayList
  • java.util.LinkedHashMap
  • java.util.HashMap
  • java.util.TreeMap

Which of the following statements regarding abstract classes are true? (check any that apply)
Note: There many be more than one right answer.
Answer

  • All methods declared in an abstract class must be abstract
  • Any subclass (abstract or concrete class) of an abstract class must implemented all the methods
    declared in the parent abstract class
  • Any concrete class must implement all the method of the parent abstract class which are not
    implemented in the super hierarchy tree
  • The abstract class may have method implementation

What will be the output of the following code:
int a = 5;
int b = a;
a*=2;
b+=1;
System.out.println(a);
System.out.println(b);
Answer

  • 10
    11
  • 10
    5

Select all true statements :
Note: There many be more than one right answer.
Answer

  • Threads exist within a process
  • Every process has at least one thread
  • Processes exist within a thread
  • A thread may belong to more than one process

What is the most restrictive access modifier that will allow members of one class to have access to members of another class in the same package?
Answer

  • public
  • protected
  • abstract
  • synchronized
  • default access

Which one of these lists contains only java programming language keywords?
Answer

  • class, if, void, long, Int, continue
  • goto, instanceof, native, finally, default, throws
  • try, virtual, throw, final, volatile, transient
  • strictfp, constant, super, implements, do
  • byte, break, assert, switch, includev

Which is the best place to store business logic and look of the page?
Answer

  • JSP page contain both business logic and display logic
  • Servlet should contain business logic and JSP page should contain only display logic
  • Servlet must contain both display logic business logic

LEAVE A REPLY

Please enter your comment!
Please enter your name here