Question

1. What happens in the Java Virtual Machine (JVM) when the following line is processed? MyClass...

1. What happens in the Java Virtual Machine (JVM) when the following line is processed?
MyClass n = new MyClass();
A. Nothing, the line is skipped, since no parameters are defined
B. An object of type MyClass is created, no reference is created
C. A reference to an object of type MyClass is created, no object is created
D. Both a reference and an object of type MyClass are created
2. Which of the following is true?
A. A single reference variable can refer to multiple objects at one time
B. Multiple reference variables can refer to the same, single object
C. An object can only be referred to by a single reference variable
D. A reference variable always refers to a valid object
3. The class "Parent" and its subclass "Child" both implement a method with header: "public String printName()", printing "parent" and "child" respectively. Which of the 4 choices below reflects the correct output of the following program:
Parent v1 = new Parent();
Child v2 = new Child();
Parent v3 = new Child();
System.out.println(v1.printName()+" "+ v2.printName()+" "+ v3.printName());
A. parent child child
B. parent child parent
C. parent parent parent
D. child parent child
4. For the program in Q3 above, what are the types of variable v3 at the compilation time and at the run time?
A. Parent Parent
B. Parent Child
C. Child Parent
D. Child Child
5. In the programs in Q3 above, is the variable v2 a reference variable?
A. Yes
B. No
6. For the program in Q3 above, if the class “Child” implements another method with header: “public void display()”. And the class “Child” wants to call the method “printName()” in the class “Parent” from its own method “public void display()”, which of the following is correct?
A. printName()
B. this.printName()
C. Parent.printName()
D. super.printName()

0 0
Add a comment Improve this question Transcribed image text
Answer #1
1. What happens in the Java Virtual Machine (JVM) when the following line is processed?
 MyClass n = new MyClass();

 A. Nothing, the line is skipped, since no parameters are defined
 B. An object of type MyClass is created, no reference is created
 C. A reference to an object of type MyClass is created, no object is created
 D. Both a reference and an object of type MyClass are created

   D. Both a reference and an object of type MyClass are created (self explanatory)
   MyClass n         --> represents reference
   new MyClass()  --> represents object

2. Which of the following is true?
 A. A single reference variable can refer to multiple objects at one time
      False - it can refer only one variable at one time
 B. Multiple reference variables can refer to the same, single object
      True - Multiple reference can refer to same/single object
 C. An object can only be referred to by a single reference variable
      False - object can be referred by multiple reference variables
 D. A reference variable always refers to a valid object
      False - May refere to valid object or it may not refer to any object

3. The class "Parent" and its subclass "Child" both implement a method with header: "public String printName()", printing "parent" and "child" respectively. Which of the 4 choices below reflects the correct output of the following program:
 Parent v1 = new Parent(); //Parent ref to parent obj
 Child v2 = new Child();   //child ref to child object
 Parent v3 = new Child();  //parent ref to child object
 System.out.println(v1.printName()+" "+ v2.printName()+" "+ v3.printName());

 A. parent child child
      parent -> printed by parent ref and object
      child -> printed by child ref and child object
      child -> printed by parent ref but child object(parent class method is overridden)
 B. parent child parent
 C. parent parent parent
 D. child parent child
4. For the program in Q3 above, what are the types of variable v3 at the compilation time and at the run time?
 A. Parent Parent
 B. Parent Child
      Compile time Parent (Since compiler does not have any idea what happens at runtime.
      Runtime time Child
 C. Child Parent
 D. Child Child
5. In the programs in Q3 above, is the variable v2 a reference variable?
 A. Yes(solution basics)
 B. No
6. For the program in Q3 above, if the class “Child” implements another method with header: “public void display()”. And the class “Child” wants to call the method “printName()” in the class “Parent” from its own method “public void display()”, which of the following is correct?
 A. printName()
 B. this.printName()
 C. Parent.printName()
 D. super.printName() -> In java super keyword is used to call the variable and methods of parent class
Add a comment
Know the answer?
Add Answer to:
1. What happens in the Java Virtual Machine (JVM) when the following line is processed? MyClass...
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
  • c. [3 marks] Given the following definition of the class MyClass, class MyClass { String s...

    c. [3 marks] Given the following definition of the class MyClass, class MyClass { String s int z Myclass(int y) { z = y } } fill in the blanks (labelled i., ii. and iii.) in the definition of the method main, of the class StringProcessing, with i. a declaration of a variable named obj of type MyClass, initialised with a MyClass object so that its instance variable z has a value of 20, ii. an assignment of the instance...

  • What is the output for the following program codes? a) [ 0.5 Mark ] class A...

    What is the output for the following program codes? a) [ 0.5 Mark ] class A { int i; } class B extends A { int j; void display() { super.i = j + 1; System.out.println(j + " " + i); }} class inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); }} OUTPUT: b) [ 0.5 Mark ] class Parent { public void getBike(){ System.out.println("Suzuki Bike"); }} class Child extends Parent {...

  • (TCO 1) The JVM executes a Java application by (Points : 6)        executing the public static...

    (TCO 1) The JVM executes a Java application by (Points : 6)        executing the public static main method of the class.        creating an object of the class and executing that object’s main method.        executing the class constructor.        compiling the Java code into byte code. (TCO 1) Which method call converts the value in variable stringVariable to a double? (Points : 6)        Double.parseDouble( stringVariable );        Convert.toDouble( stringVariable );        Convert.parseDouble( stringVariable );        Float.parseFloat( stringVariable ); (TCO 1) Which of the following can...

  • 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...

  • Question 1 1 pts Which of the following is not a valid class name in Java?...

    Question 1 1 pts Which of the following is not a valid class name in Java? O MyClass MyClass1 My_Class MyClass# Question 2 1 pts Which of the following statements is False about instance variables and methods? Instance variables are usually defined with private access modifier. Instance variables are defined inside instance methods. Instance methods are invoked on an object of the class that contains the methods. A class can have more than one instance variables and methods. Question 3...

  • Java Questions When creating a for loop, which statement will correctly initialize more than one variable?...

    Java Questions When creating a for loop, which statement will correctly initialize more than one variable? a. for a=1, b=2 c. for(a=1, b=2) b. for(a=1; b=2) d. for(a = 1&& b = 2) A method employee() is returning a double value. Which of the following is the correct way of defining this method? public double employee()                                    c. public int employee() public double employee(int t)                  d. public void employee() The ____ statement is useful when you need to test a...

  • IN JAVA 2 A Binary Search Tree The goal of this lab is to gain familiarity...

    IN JAVA 2 A Binary Search Tree The goal of this lab is to gain familiarity with simple binary search trees. 1. Begin this lab by implementing a simple class that represents a "node” in a binary search tree, as follows. public class MyTreeNode<t extends Comparable<T>> { public T data; public MyTreeNode<T> leftchild; public MyTreeNode<T> rightChild; public MyTreeNode<T> parent; 2. Have the second member of your pair type in the code for the simple binary search tree interface. public interface...

  • Java please answer A to I please dont type the answer on paper please use the...

    Java please answer A to I please dont type the answer on paper please use the computer A.   Explain why alpha cannot be accessed by other members of its class. B.   In the program, how can you determine the type of access modifier? C.   Describe the differences and similarities of beta and gamma in program, within the context of access specifiers and class member accessibility. D.   Explain how objects, a and b, are passed to the method. E.    Why...

  • 1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program!...

    1) Consider the following Java program: 1 public class HelloWorld { 2     // My first program! 3     public static void main(String[] args) { 4         System.out.println("Hello, World!"); 5     } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...

  • 1. What is output by the following code: ArrayList< Integer > a = new ArrayList< Integer...

    1. What is output by the following code: ArrayList< Integer > a = new ArrayList< Integer >(); ArrayList b = a; a.add(new Integer(4)); b.add(new Integer(5)); a.add(new Integer(6)); a.add(new Integer(7)); System.out.println(b.size()); A)1 B)2 C)3 D)4 E)5 2. Assume the Student and Employee classes each extend the Person class. The Student class overrides the getMoney method in the Person class. Consider the following code:     Person p1, p2, p3;     int m1, m2, m3;     p1 = new Person();     m1 = p1.getMoney();     // assignment 1...

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