Java | JSP | JSF Answers

Questions answered by Experts: 3 611

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search

Disadvantages of using microservices


Write a Java code that creates a variable of int type named 'mode' and sets its initial value to 12. Create a method named 'setTime()' of void type that take four parameters: (1) one int parameter named 'h', (2) one int parameter named “m”, (3) one int parameter named “s”, and (4) one char parameter named 'ap'. In the body of the “setTime()” method, use an if statement to check whether or not the value of “h” is greater than or equal to 12. If so, subtract 12 from 'h'. Then, assign 12 as value to the 'mode' variable. Display the value of hour, minute, second, and AM/PM being set as well as the mode. Create another form of 'setTime()' method of void type that take only three parameters: (1) one int parameter named 'h', (2) one int parameter named 'm', and (3) one int parameter named 's'. In the body of the 2nd form of 'setTime()' method, assign 24 as value to the 'mode' variable. Display the value of hour, minute, and second being set as well as the mode.


Create Java program that has “supporting class” named “Point3D” which contains:

(a) three class variables, x, y, and z. (b) a default constructor that automatically set the point to be (0, 0, 0). (c) create another form of the default constructor that allows the user to set the three coordinates, such as (126, 44, 39) (d) create method named “distance” that calculates the distance between (0, 0, 0) and another point such as (31, 127, 86); and create another form of the “distance” method that calculates the distance between one “Point3D” object and another “Point3D” object.

In the man() method create three instances of the “Point3D” class: p1, p2, and p3. Let p1 be (0, 0, 0), p2 be (126, 44, 39), and p3 be (25, 219, 74). Ask the user to enter three integers, and then use them to create another Point3D object named “p4”. Calculate the distance between p1 and p2, p1 and (31, 127, 86), p2 and p3 as well as p3 and p4.


10. Given the following code, the output is __. Please select "A, B, C, D, or E" as correct option. 


class Parent

{

private int x = 5;

int show() { x = 6; return x; }

}

class Child extends Parent

{

public int x = 7;

public Child() { x = 8; x++; x = super.show(); }

}

class Sample

{

public static void main(String[] args)

{

Child c1 = new Child();

System.out.print(c1.x);

}

}


A. 5

B. 6

C. 7

D. 8

E. 9


9. In order to override a method but still use the method in the superclass, what keyword

should be used? Please select "A, B, C, D, or E" as correct option. 


A. main

B. void

C. super

D. static

E. protected


8. When overriding a method, where should the new method be defined? Please select "A, B, C, D, or E" as correct option. 


A. In the superclass

B. In the main class

C. Outside the main class

D. In the subclass

E. Whichever class the programmer prefers


7. Given the following code, which statement is correct? Please select "A, B, C, D, or E" as correct option. 


class Sample

{

int add(int x, int y) { return x+y;} // form 1

String add(String x, String y) { return (x+y)+""; } // form 2

double add(int x, int y, int z) { return x+y+z; } // form 3

void add(int x) { System.out.print(x); } // form 4

}


A. form 1 has a conflict with form 2 because parameters in form 2 are different from

parameters in form 1.

B. form 1 has a conflict with form 3 because the number of parameters in form 3 is not equal

to that of form 1.

C. form 2 is the one that will cause conflicts with others because String is not a primitive data

type.

D. form 4 is the one that will cause conflicts because it is the void type.

E. There is no conflict among these four forms.


6. Given the following code, which form of the "add" method can generate 3.24.1 as output? Please select "A, B, C, D, or E" as correct option. 


class Sample

{

int add(int x, int y) { return (x + y); } //form1

float add(float x, float y) { return (x + y); } //form2

double add(double x, double y) { return (x + y); } //form3

char add(char x, char y) {return (char)((int) x + (int) y);} //form4

String add(String x, String y) { return (x + y); } //form5

..........

}


A. form 1

B. form 2

C. form 3

D. form 4

E. form 5


5. Given the following code, which form of the "add" method will be called for execution?


class Sample

{

int add(int x, int y) { return (x + y); } //form1

float add(float x, float y) { return (x + y); } //form2

double add(double x, double y) { return (x + y); } //form3

boolean add(boolean x, boolean y) { return x; } //form4

public static void main(String[] args)

{

Sample s1 = new Sample();

System.out.print(s1.add(3.2, 4.1));

}

}


A. form 1

B. form 2

C. form 3

D. form 4

E. None of the options


4. Which access modifier can prevent methods of a class being overridden? Please select "A, B, C, D, or E" as correct option. 


A. public

B. private

C. static

D. protected

E. final


LATEST TUTORIALS
APPROVED BY CLIENTS