Question

I. [15%) Which one causes compilation is deleted, what is the output when the program is executed? statement from sl to s6 (see below) cause compilation error? Assume the statement that class X void 120 f System.out.println(XXX);3 Answeri The statement causes compilation errors: class Y extends X void £20 1 System.out.printin(YYY); void f30 &System.out.printinAAA): class Z extends Y void 120 ( System.out.printinzzz; void 130 System.out.println(BBB); The output of the program (after the statement that causes compilation is deleteod) class Testf static void g(Object a) X aa- (X) a; aa.fl0: public static void main(String argsD Object obj-new Y0: obj.toString0 g(obj); obj = new ZO; obj.30: g(obj); s1 I/ s2 Il s3 I/ s4 Il s5 / s6
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Out of all the statements, s5 gives compilation error. Because, Now obj of Object iass assigned to class Z();
We are usign the parent class object to call a method in teh subclass. It only works when the parent class has the same method(f3) defined. i.e This call would only work when Object class has the method f3.

So, answer is s5

class Test static void g (Object a) f X aa= (X) a; aa.fl public static void main (String[l args) object obj new Y obj.toStrin

Add a comment
Know the answer?
Add Answer to:
I. [15%) Which one causes compilation is deleted, what is the output when the program is...
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
  • i think from the very bottom part there, they just want to know what the output...

    i think from the very bottom part there, they just want to know what the output would be when you call the main() method of the Maryland class workout actually running it. 2. Consider the following code fragment taken from some package: public class Maryland extends State { Maryland() /* null constructor */ ) public void printMe() ( System.out.printin("Read it."); } public static void main(String[] args) Region mid = new State(); State md new Maryland(); Object obj new Place(); Place...

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

  • What is the output of this program? class A { public int i; private int j;...

    What is the output of this program? class A { public int i; private int j; } class B extends A { void display() { super.j = super.i + 1; System.out.println(super.i + " " + super.j); } } class Inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } } Java language!! // include explanation!

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

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

  • Question 1 (5 points) Question 1 Unsaved What is displayed on the console when running the...

    Question 1 (5 points) Question 1 Unsaved What is displayed on the console when running the following program? public class Quiz2B { public static void main(String[] args) { try { System.out.println("Welcome to Java"); int i = 0; int y = 2 / i; System.out.println("Welcome to Java"); } catch (RuntimeException ex) { System.out.println("Welcome to Java"); } finally { System.out.println("End of the block"); } } } Question 1 options: The program displays Welcome to Java two times. The program displays Welcome to...

  • 12. Predict the output generated at the marked println lines in the following program. The program...

    12. Predict the output generated at the marked println lines in the following program. The program makes use of the class Employee that is also given. Please enter your answers in the space provided below the code. public class Employee { private String name; private double salary; public Employee(String name, double salary) { this.name = name; this.salary = salary; } public String getName() { return name; } public double getSalary() { return salary; } public void raiseSalary(double percent) { double...

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

  • java Use the classes given in the previous question and write the output tha t is...

    java Use the classes given in the previous question and write the output tha t is generated when this program is run. You may write your answer as "Elaine 2 Jerry 1" or "Compiler Error" or "Runtime Error" If there is an error then explain why. public class Main{ public static void main(String args[]){ Object o = new Kramer(); ((George)(o)).method1(); ((Jerry)(o)). method1(); 0.method2(); public class George extends Elaine {! public void method1() { System.out.print("George 1 "); public class Jerry {...

  • What output is produced by the following program? public class MysteryNums public static void main(String[] args)...

    What output is produced by the following program? public class MysteryNums public static void main(String[] args) - int x = 12; int y = x - 3; 3, sentence (y, x + y); . public static void sentence (int numi, int num2) { 4: System.out.println(num1 + " + num2);

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