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 & Filtering

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


3. The following is an example of __. Please select "A, B, C, D, or E" as correct option. 


class Dog

{

int bark() { ... }

}

class Poodle extends Dog

{

double bark() { ... }

}


A. method overloading

B. method overriding

C. method overloading and overriding

D. class overloading

E. class overriding


2. Given the following code, where does the method overloading happen? Please select "A, B, C, D, or E" as correct option. 


class Parent

{

public int show() { ... }

public int showIt(int x) { ... }

public int showMe() { ... }

public double showHow() { ... }

public void showAgain() { ... }

}

class Child extends Parent

{

public int show(int x) { ... }

public int showIt(int x) { ... }

public int showMe() { ... }

public int showHow() { ... }

public double showHow() { ... }

}


A. the superclass

B. the Parent class

C. the subclass

D. both the Parent and Child class

E. both the superclass and subclass


LATEST TUTORIALS
APPROVED BY CLIENTS