Question

1.   What will be the value of x after the following code is executed? int x...

1.   What will be the value of x after the following code is executed?

int x = 10, y = 20;
while (y < 100)
{
x += y;
}

A.   90
B.   110
C.   210
D.   This is an infinite loop

2.   If a superclass has constructor(s):
A.   then its subclass must initialize the superclass fields (attributes).
B.   then its subclass must call one of the constructors that the superclass does have.
C.   then its subclass does not inherit public fields (attributes) from the superclass.
D.   then its subclass must contain the default constructor for the superclass.

3.   Which of the following is a correct method header for receiving a two-dimensional array as an argument?
A.   public static void passArray(int[1,2] a)
B.   public static void passArray(int [][] a)
C.   public static void passArray(int[1],[2])
D.   public static void passArray(int[] a, int[] b)

4.   What will be returned from the following method?

public static float[] getValue(int x)

A.   A float type value
B.   An address of an array object with float type values
C.   An int type value
D.   An array of int type values

5.   Assume the class Rectangle has been created, and the following statement correctly creates an object of the class:

Rectangle rectangle = new Rectangle();
System.out.println(rectangle);

What is true about the following statement?

A.   The method will display unreadable binary data on the screen.
B.   A compiler error will occur.
C.   The rectangle object’s toString method will be implicitly called.
D.   A runtime error will occur.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1.   

D.   This is an infinite loop

Y is not incremented inside the loop .

2.
A.   then its subclass must initialize the superclass fields (attributes).
super() is the call to superclass constructor.

3.   
B.   public static void passArray(int [][] a)
[][] denotes two dimensional array

4.   

B.   An address of an array object with float type values
float[] is any array of float data type

5.   

C.   The rectangle object’s toString method will be implicitly called.

Do ask if any doubt. Please up-vote.

Add a comment
Know the answer?
Add Answer to:
1.   What will be the value of x after the following code is executed? int x...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Java Which of the following statements declares Salaried as a subclass of payType? Public class...

    In Java Which of the following statements declares Salaried as a subclass of payType? Public class Salaried implements PayType Public class Salaried derivedFrom(payType) Public class PayType derives Salaried Public class Salaried extends PayType If a method in a subclass has the same signature as a method in the superclass, the subclass method overrides the superclass method. False True When a subclass overloads a superclass method………. Only the subclass method may be called with a subclass object Only the superclass method...

  • What is the code for this in Java? Assignment Inheritance Learning Objectives Declare a subclass that...

    What is the code for this in Java? Assignment Inheritance Learning Objectives Declare a subclass that derives from a superclas:s ■ Demon "Declare a variable of the superclass type and assign it an instance of the subclass type strate polymorphic behavior Access the public members of the superclass type Notice how the overridden versions of the subclass type are called Notice how the subclass specific members are inaccessible "Create an array of superclass type and use a foreach loop to...

  • Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array...

    Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array double[10]; c. charl charArray "Computer Science"; None of the above Analyze the following code: class Test public static void main(Stringl] args) System.out.println(xMethod(10); public static int xMethod(int n) System.out.println("int"); return n; public static long xMethod(long n) System.out.,println("long"); return n The program displays int followed by 10 The program displays long followed by 10. The program does not compile. None of the above. tions 3-4 are...

  • In the following program: public  class Problem2{     public static int sample(int x, int y){         int z;         .........

    In the following program: public  class Problem2{     public static int sample(int x, int y){         int z;         ......      }     public static void  main(String[] args)     {          int a, b;          ......          sample(a,b);     } } (1) What is the return type of sample? (2) What are the local variables of sample? (3) What are the parameters of sample? (4) What are the arguments of sample? (5) Is sample a per-object method? Or a per-class method? (6) Is sample a public method, or private method?

  • Question 1 What is the value of x after the following int x = 5; x++;...

    Question 1 What is the value of x after the following int x = 5; x++; x++; x+=x++; A)14 B)10 C)13 D)15 Question 2 The last line in value returning function (before the }) should contain the word return. True False Question 3 This contains three parts: Void or Data Type the name optional parameter list A)Menu System B)Function Header C)Switch Question 4 What is a variable? A)a pointer B)a place in memory to hold data C)int D)a computer programming...

  • JAVA 1.            Given the following class definition, what are the contents of the fields x and...

    JAVA 1.            Given the following class definition, what are the contents of the fields x and y of the object p ?    class MyPoint {      int x;      int y; public MyPoint (int x, int y){        x = x;        y = y;      } --------------------------------------- MyPoint p = new MyPoint( 100, 88 ); 2.            static and non-static members What would happen if you tried to compile and run the following code ? public class Driver {...

  • 1. What is the output when you run printIn()? public static void main(String[] args) { if...

    1. What is the output when you run printIn()? public static void main(String[] args) { if (true) { int num = 1; if (num > 0) { num++; } } int num = 1; addOne(num); num = num - 1 System.out.println(num); } public void addOne(int num) { num = num + 1; } 2. When creating an array for primitive data types, the default values are: a. Numeric type b. Char type c. Boolean type d. String type e. Float...

  • please this is Java and i need help Question 5 public class Food { public void...

    please this is Java and i need help Question 5 public class Food { public void Foodmethod_1 (int i) { public void Foodmethod_2 (int i) { } public static void Foodmethod_3(int i) { public class Bankudade extends Food { public static void Foodmethod_1 (int i) { public void Foodmethod_2 (int i) { public void Foodmethod_3 (int i) { > 7 a) Determine which method in the subclass overrides a method in the super class? (6 marks) EV b) Determine which...

  • 1) In the Quiz class, the foo method has the following API: public void foo( int...

    1) In the Quiz class, the foo method has the following API: public void foo( int x, String s) Which method call(s) would be correct assuming both a and y are integer values and assuming each statement is complete? a. Quiz q = new Quiz(); a = q.foo( y, “Maybe?” ); b. Quiz q = new Quiz(); q.foo( 1, “Hmmm!” ); c. Quiz q = new Quiz(); Quiz.foo( y, “You think” ); d. Both b and c 2) In the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT