Question

JAVA MCQ QUESTION
WHAT IS THE ANSWER AND WHY

22. Consider the following code: public class C public int myVar; public void outerMethod) int myVar--1 Something x- new Some

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

The Answer is A) this.myVar = ...

WHY ::..

Not B) because myVar in the sense it check's out the variable named myVar in the local scope , inside the outerMethod

Not C,E) The variable is this class only not in the super class , And also This class C is not a subclass of any super class

So C,E are incorrect and in spite of these The notation E is syntactically incorrect

Finally ::..

Actually the myVar belongs to the class C

So if we want to refer that variable from outside of the class then we refer it as C.myVar

but we are inside of the class , in a method ,

this -> is used to refers the present class

so out task is to refer the variable which is in the class, in which we are presently at

So the reference is this.myVar ; varaible names myVar in the present class means class in which the method is in

For better understanding about super class ;  

1.java 1 public class Superclass 2 public int myVar 1 0 5 // Here super class for class subClass is superClass 6 public cl

Add a comment
Know the answer?
Add Answer to:
JAVA MCQ QUESTION WHAT IS THE ANSWER AND WHY 22. Consider the following code: public class...
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
  • Java question Consider the following code segment. public class KaBoom { public int b; public void...

    Java question Consider the following code segment. public class KaBoom { public int b; public void m1 () {//Your code goes here } public void m2 (KaBoom k) { System, out. print In (k. b); } } Complete the method body of m1 () indicated by the comment line. The m1 () method simply calls the m2 () method by passing in the current KaBoom object variable to m2 ().

  • Consider the following Java 8 code, and select true statements: public interface Functionlnterfac...

    Consider the following Java 8 code, and select true statements: public interface Functionlnterface1 void abstFun1 (int x) public interface Functioninterface2( void abstFun2(int x); public class Main implements Functioninterface2( @Override public void abstFun2(int x) System.out.printin(3'x); public static void main(Stringl args) ( Functioninterface1 fobj (int x)->System.out.printin(2"x) fobj.abstFun1(5); Main me - new Main; me.abstFun2(5); Functioninterface2 fobj2-(int x)->System.out.printin(4%; fobj2.abstFun2(5) 2 in main will not run because abstFun2 was previoudly implemented. O The fobj instance of Functionlnterface1 is created using the lambda at runtime without...

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

  • the answer must be in java. thank you Question 2 [8 points] Consider the class Class...

    the answer must be in java. thank you Question 2 [8 points] Consider the class Class A below: class Class A implements Serializable{ int a; static int b; transient int c; String s; // Constructor public Class A (int a, int b, int c, Strings){ this.a = a; this.b = b; this.c = c; this.s = s; Complete the class Test to test the serialization and deserialization of the objects of class Class A. State the possible variable values following...

  • Consider the following Java classes: class A{ public int foo () { return 1; } public...

    Consider the following Java classes: class A{ public int foo () { return 1; } public void message () { System.out.println( "A" + foo()); } } class B extends A { public int foo() {return 2; } } class C extends B { public void message () { System.out.println( "C" + foo()); } } (i) What are the outputs of the following code? (ii) What would be the outputs if Java used static dispatching rather than dynamic dispatching? B b...

  • Please answer this question (JAVA) Consider now the following code fragment: 1 public class Main public...

    Please answer this question (JAVA) Consider now the following code fragment: 1 public class Main public static void main(String args) Person p; 2 3 pnew Person [2]; for (int i 0; i < p.length; i++) 3 пеw Person("A", "B", "С"); System.out.println(p [0].toString ()); 5 plil 6 8 9 10 6. What is the value of 'p' after line 3? (a) Something like "Person@42gf32" (b) null (c) A memory location 7. What is the value of 'p' after line 4? (a)...

  • ndicate the correct answers bases on the following code: public class IdentifyMyParts { public static final...

    ndicate the correct answers bases on the following code: public class IdentifyMyParts { public static final int X = 7; public int y ; public void display(){.......} } public static void main(){string [] args){ IdentifyMyParts Obj1; Obj1.X=8; Obj1.y=20; } a. IdentifyMyParts is a class b. X is a instance method c. y is an instance variable d. Obj1.X=100; e. Obj1.y=200; f. display() is a member function

  • What is wrong with the following Java Code. public class TestEdible { abstract class Animal {...

    What is wrong with the following Java Code. public class TestEdible { abstract class Animal { /** Return animal sound */ public abstract String sound(); } class Chicken extends Animal implements Edible { @Override public String howToEat() { return "Chicken: Fry it"; } @Override public String sound() { return "Chicken: cock-a-doodle-doo"; } } class Tiger extends Animal { @Override public String sound() { return "Tiger: RROOAARR"; } } abstract class Fruit implements Edible { // Data fields, constructors, and methods...

  • please evaluate the following code. this is JAVA a. class Car { public int i =...

    please evaluate the following code. this is JAVA a. class Car { public int i = 3; public Car(int i) { this.i = i; } } ... Car x = new Car(7), y = new Car(5); x = y; y.i = 9; System.out.println(x.i); b. class Driver { public static void main(String[] args) { int[] x = {5, 2, 3, 6, 5}; int n = x.length; for (int j = n-2; j > 0; j--) x[j] = x[j-1]; for (int j...

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

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