1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
KiRa [710]
4 years ago
12

question 4 What is the output of following program: public class Test { public static void main(String[] args) { A a = new A();

a.methodB(); } } class A { public A() { System.out.println("A's constructor is executed"); } public void methodA() { System.out.println("methodA is executed"); } public void methodAB() { System.out.println("A's methodAB is executed"); } } class B extends A { private int num = 0; public B() { super(); System.out.println("B's constructor is executed"); } public B (int n) { num = n; System.out.println("B's constructor is executed"); } public void methodB() { System.out.println("num is " + num); System.out.println("methodB is executed"); } public void methodAB() { System.out.println("B's methodAB is executed"); } }
Computers and Technology
1 answer:
beks73 [17]4 years ago
8 0

Answer:

The answer to this question can be given as:

This program will give an error message that is cannot find symbol.

a.methodB(); //error  

Explanation:

In this question, the program will give an error message that is cannot find symbol. Because in this question there are three class Test, class A, and class B. In this question first, we explain class A and class B then the class Test. In class A we create constructor then we create two methods that is methodA() and methodAB(). In the constructor and methods, we print  the message.  In class B class inherits class A. In this class we declare an integer variable that is used as a parameter in the parameterized constructor. but first, we declare the default constructor then parameterized constructor. In the default constructor, we use the super keyword. Super keyword is  used to call the above class method or constructors. Then we declare the two methods that are methodB() and methodAB ()  in these methods we print messages.  Then we define the main class that is the class Test. In this class, we define the main method and create class A object and call the class B method. that is not possible in java.

You might be interested in
What is the condition for setting an alarm clock
stich3 [128]

Answer:

The time in which the alarm clock will sound

Explanation: Hope this helped please give me brainliest

6 0
3 years ago
Online Book Merchants offers premium customers 1 free book with every purchase of 5 or more books and offers 2 free books with e
andrey2020 [161]

Answer:

This question has two parts, first part is about programming about a Player class and second for reading string from user and decide how many time duck string entered by user and terminate if user press goose string.

The explanation of both program (executable code) is given below in explanation section.

Explanation:

//Program 1

#include <iostream>

using namespace std;

int main()

{

 bool isPremiumCustomer;

 int nbooksPurchased;

 int totalBookPurchasedWithOffer;

// bool cutomerType;

 int freeBooks;

 cout<<"Press 1 for Premium Customer and 0 for regular Customer";

 cin>>isPremiumCustomer;

 cout<<"How many books you purchased ";

 cin>>nbooksPurchased;

 

 

switch(isPremiumCustomer)// what type of customer is  

{

case 1://if customer is premium

 if (nbooksPurchased >= 5&&nbooksPurchased<8)// purchase book greater between 5 and 8

  {

   freeBooks=1;//offer free book

   totalBookPurchasedWithOffer=nbooksPurchased+freeBooks;//total number of book including free book

   

   cout<<"You purchased total book with offer ";//show total books

   cout<<totalBookPurchasedWithOffer;

  }

   

  else if (nbooksPurchased >= 8)//if premium customer purchase more than 8 book

    {

    freeBooks=2;//offer two free book

    totalBookPurchasedWithOffer=nbooksPurchased+freeBooks;//total number of book including free book

    cout<<"You purchased total book with offer ";

    cout<<totalBookPurchasedWithOffer;//show total books

    }

  else{

   cout<<"You purchased total book with no offer ";

    cout<<nbooksPurchased;

   }

  break;

case 0:// if customer is regular customer

 if (nbooksPurchased >= 7&&nbooksPurchased<12)//and purchase book between 7 and 12

  {

   freeBooks=1;// offer 1 free book

   totalBookPurchasedWithOffer=nbooksPurchased+freeBooks;

   cout<<"You purchased total book with offer ";

   cout<<totalBookPurchasedWithOffer;

  }

   

  else if (nbooksPurchased >= 12)//if purchase 12 or more than 12 book

    {

    freeBooks=2;//offer two free book

    totalBookPurchasedWithOffer=nbooksPurchased+freeBooks;

    cout<<"You purchased total book with offer ";

    cout<<totalBookPurchasedWithOffer;

    }

 else{

  cout<<"You purchased total book with no offer ";

  cout<<nbooksPurchased;

  }

  break;

 

}

 

 

 

return 0;// terminate the program

 

}

/* program 1 has ended

and program 2 is started from here

#######################################################

*/

#include <iostream>

using namespace std;

int main()

{

string readstring;// take input string from user to enter either "goose" or "duck"

int count=0;//count the number of "duck"

while(readstring!="goose")//run loop, until user do not enter string  

{

 cout<<"Enter the string either goose or duck ";// prompt user to enter the string

 cin>> readstring;// read string from user

 if (readstring=="duck")//if string equal to "duck"

 {

  count=count+1;//count number of duck string enter by user

   

 }

}//exit/terminate the loop, if user enter the goose string

cout<< " Number of duck that were read " ;// show how many duck string entered by user

cout<<count;

return 0;// terminate the program

 

}

6 0
3 years ago
List the main industries in Sierra Leone​
Dafna11 [192]

Answer:

The main industries in Sierra Leone are: Diamond mining

Petroleum refining

Small - scale manufacturing (beverage, textiles,footwear)

Explanation:

They also engage in commercial ship repair

3 0
3 years ago
To add a new guide to the slide press ____________________ and then drag an existing guide
Reptile [31]
To be able to add new guide to the slide, press [Ctrl] and then drag an existing guide. Make sure that the guide is visible to your power point first so you can be able to do this. Guides in the power point is consist of 2 lines, the horizontal line and the vertical lines, once this set to appear, it will be visible to all your slides. <span />
8 0
3 years ago
Write your own SportsCar class that extends the Car class. This new class should have the following unique protected instance va
Rus_ich [418]

Answer:

class SportsCar extends Car {

   

   protected String myColor;

   protected float myEngine;

   protected String mySuspension;

   protected String myTires;    

}

Explanation:

With the provided information the class can be written as above.

Create a class called SportsCar. Since it extends from the Car, you need to type extends Car after the class name. This implies that it is a subclass of the Car class.

Then, declare its protected variables:

a string called myColor that will hold the color,

a float myEngine that will hold the engine size

a string mySuspension that will hold the suspension type

a string myTires that will hold the tire type

8 0
3 years ago
Other questions:
  • Assume that a program consists of integer and floating-point instructions. 60% of the total execution time is spent on floating
    7·1 answer
  • PLS HELP!!
    13·1 answer
  • If you need to set up direct deposit, which information from your check would you likely need?
    14·1 answer
  • Technologies that allow for instant worldwide communication include satellite and computer systems. mobile phones and internet a
    8·2 answers
  • A user found that their personal data had been exfiltrated from their computer by a malicious program that they clicked on sever
    12·1 answer
  • What process does a system use to officially permit access to a file or a program CIS 502 ?
    11·1 answer
  • Alcohol _____________.
    10·1 answer
  • Will Give Brainliest
    10·1 answer
  • Which of the following should be clicked to open Backstage View?
    7·2 answers
  • Label the parts of the plated salad.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!