Question

1. Please fill in the cells according to the given statements for each row. If the statement runs correctly, it returns true

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

All the subclasses inherited from a superclass are its instance. Also, as subclasses are instance of super class, subclass variable can be assigned to a variable of superclass.

Statements Compiler Time Error Runtime Error Output (true/false)
return (x instance of B); true (x is of X class which inherits from C which inherits from B)

B b = x;

return (b instanceof C);

true (x is assigned to B but it retaines value of X => it inherits from C)

B b = x;

Y y = (Y) b;

return (y instanceof B);

x can be converted to X again but X and Y have no relation. But as the variable b could have been of class Y, this error is not caught at compile time.
return (x instanceof Y); .X and Y have not relation and as this could be caught at compiler time itself. At compile-time that it will never be true. Therefore, it is assumed that this is not what the programmer meant

Y y = x;

return (y instanceof B);

X cannot be typcasted to Y as they do not share any relation.
Add a comment
Know the answer?
Add Answer to:
1. Please fill in the cells according to the given statements for each row. If the...
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
  • ceinterface Interface1 Abstract eeinterfaces Interface ceinterface Interface Classi Class Class3 Classe Interfacet obji - new class3();...

    ceinterface Interface1 Abstract eeinterfaces Interface ceinterface Interface Classi Class Class3 Classe Interfacet obji - new class3(); Abstracti obj2 = new Class1(); object obj3 = new Class2); class3 obj4 new Class4(); a) [1 pt) Is obji instanceof Interface? O True O False O True O False b) f1 pt) Is obj3 instanceof Interface1? c) (1 pt] Is obj4 instanceof Interfaces ? O True O False d) (1 pt) Is obj2 instanceof Interface1? O True False e) (2 pts each] State the...

  • PLEASE COMPLETE IN C++ LANGUAGE Location row : int = -1 col : int = -1...

    PLEASE COMPLETE IN C++ LANGUAGE Location row : int = -1 col : int = -1 setLocation(row : int, col : int) getRow(): int getColl): int isEmpty(): bool Details Write all the code necessary to implement the Location class as shown in the UML Class Diagram to the right. Do this in a project named snake (we'll continue adding files to this project as the term progresses). Your class definition and implementation should be in separate files. When complete, you...

  • please help Question 2 (1 point) Saved Choose the option that best describes what happens when...

    please help Question 2 (1 point) Saved Choose the option that best describes what happens when the bolded println() statement is executed: public class Point { public static void main(String[] args) { Point p 1 = new Point(3, 4); System.out.println(p1); } public int x, y; public Point(int xx, int yy) { x = xx; y = yy; } سی Point inherited a toString() method, which is called internally by println(). This is a compile error - println doesn't know how...

  • Write true or false for each of the following statements. Provide justification for each answer—if true,...

    Write true or false for each of the following statements. Provide justification for each answer—if true, give a brief explanation. If false, either provide a counterexample or contrast the statement with a similar true statement, explaining why the two cases differ. (5 points) The column space of any n x n matrix A with det(A) # 0 is equal to its row space .

  • 1 Suppose you are designing a set of classes intended to represent a solar system and...

    1 Suppose you are designing a set of classes intended to represent a solar system and the planets and comets within it. Which of the following class structures is a correct representation? public class Comet { ... } public class Planet { ... } public class SolarSystem extends Planet { ArrayList <Comet> comets; ... } public class Planet { ... } public class Comet { ... } public class SolarSystem { ArrayList <Planet> planets; ArrayList <Comet> comets; ... } public...

  • 8.18 Ch 8, Part 3: Tabular Output Write this program using Eclipse. Comment and style the...

    8.18 Ch 8, Part 3: Tabular Output Write this program using Eclipse. Comment and style the code according to CS 200 Style Guide. Submit the source code files (.java) below. Make sure your source files are encoded in UTF-8. Some strange compiler errors are due to the text encoding not being correct. The program you are going to write will produce a String containing a tabular representation of a 2D String array. For the 2D arrays, assume that the first...

  • The method m() of class B overrides the m() method of class A, true or false?...

    The method m() of class B overrides the m() method of class A, true or false? class A int i; public void maint i) { this.is } } class B extends A{ public void m(Strings) { 1 Select one: True False For the following code, which statement is correct? public class Test { public static void main(String[] args) { Object al = new AC: Object a2 = new Object(); System.out.println(al); System.out.println(a): } } class A intx @Override public String toString()...

  • In each of the following questions, first use NetBeans IDE to run the code (if there...

    In each of the following questions, first use NetBeans IDE to run the code (if there is an error fix it) then take a screenshot of the output and paste it under (A). In (B), justify the output you obtained in (A). - 9. Given the following: public class WorkingSheet {     public static void main(String[] args) {        B myB = new B();        A myA = new B();        System.out.print(myB instanceof A);        System.out.print(myB instanceof C);        System.out.print(myA...

  • linear algebra class due in 30minutes please help ASAP! Determine whether each statement is true or...

    linear algebra class due in 30minutes please help ASAP! Determine whether each statement is true or false. If a statement is true, give a reason or cite an appropriate statement from the text. If a statement is false, provide an example shows the statement is not true in all cases or cite an appropriate statement from the text. (a) To find the determinant of a triangular matrix, add the entries on the main diagonal false, the determinant of a triangular...

  • QUESTION 3 Assume x = 4 and y = 5, which of the following is true?...

    QUESTION 3 Assume x = 4 and y = 5, which of the following is true? x < 5 || y < 5 x > 5 || y > 5 x < 5 && y < 5 x > 5 && y > 5 QUESTION 14 Which of the following statements are the same? (A) x -= x + 4 (B) x = x + 4 - x (C) x = x - (x + 4) (A) and (B) are...

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