Q.1)
Solution)Option C 2 is the correct answer
Explanation:
i)The first print statement is wrong since this refers to the current scope and there is no variable price in MyProg.
ii)The second print statement is wrong since the class MyProg has the superclass object(Every class in java is a subclass of object) and there is not variable price there.
iii)The third print statement is wrong since MyProg is in package 2 and price has a access modifier of default which has a visibility of same package and not in different package and Apple and MyProg are in different package.
iv)The fourth print statement is correct since weight is public in Fruit and it can be accessed outside the package also.
v)The fifth print statement is also correct since a.getPrice() is public in Fruit and it can be accessed outside the package also.
Q.2)
Solution)Option C 9 is the correct answer
Explanation: When a base class is instantiated its superclass constructor also gets called and thus for each Gala object created each constructor of Apple and Fruit gets called and thus three print statements are executed for each object creation, here two Gala objects are created and thus 6 print statements and 3 more print statements thus total 9 print statements are executed.Consider the output below for prioper reference:

NOTE:Please upvote if you liked my answer and comment if you need any modification or explanation.
Q1. How many printing statements are ok to be executed? A. O B. 1 C. 2...
**JAVA*JAVA Question 1 How many k's values will be printed out? public static void main(Stringl args) for (int k-1: k10:k if (k8) continue: System.out.println k) Question 2 3.5 pts Analyze the following code. Which one is correct? package p public class A package p2: import p1. public class B extends Af int i- 5 private int j- 10: public A0I public static void main(Stringll args) B b new B0: System.out.println(a.i+", "+ajt", "+b.it""+bj): a.i is printable None of them b.i is...
Exercise 1): take the program “InteractiveCounting” (attached). Your task is to change the implementation of both the “ReadInput” and the “Count” classes. Currently these classes extends Thread. You should now use the Runnable interface to implement the thread. The output of the program should not change. I have also attached the class ThreadType2 to give you a working example on how to implement a thread using the Runnable interfacethe program is here package threadExamples; import java.util.Scanner; public class InteractiveCounting {...
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...
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...
Java -Create an interface and implement it In the murach.db package, create an interface named IProductDB. This interface should specify this abstract method: public abstract Product get(String productCode); Modify the ProductDB class so it implements the IProductDB interface. Write the code for the new ‘get’ method. Then remove the getProductByCode method. In the Main class, modify the code so it works with the new ProductDB class. This code should create an instance of the IProductDB interface like this: IProductDB db...
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 {...
help me with a question in java: class A { int i = 10; } class B extends A { int i = 20; } public class Boo { public static void main(String[] args) { A a = new B(); System.out.println(a.i); } }
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()...
Below, you can find the description of your labwork for today. You can also find the expected output of this code in the Application Walkthrough section. You are going to improve your existing Money & Stock Trading Platform on previous week’s labwork by incorporating Collections. In previous labworks, you have used arrays for holding Customer and Item objects. For this labwork you need to use ArrayList for holding these objects. So, rather than defining Customer[] array, you need to define...
I need help to write a test case. 1. Go to the ConcertTicketTest.java file and write test cases for the compareTo method you just implemented. /* ConcertTicket.java file */ package SearchingSorting; /** * * @author clatulip */ public class ConcertTicket implements Comparable<ConcertTicket> { private String name; private int price; private char row; private int seat; public ConcertTicket(String name, int price) { this.name = name; this.price = price; // randomly create a row and seat // assumes 60 seats across width...