Question

In: Computer Science

When I wrote this code in the Eclipse program, I did not see a output .....

When I wrote this code in the Eclipse program, I did not see a output .. Why?

_______
public class AClass
{
private int u ;
private int v ;
public void print(){
}
public void set ( int x , int y )
{
}
public AClass
{
}
public AClass ( int x , int y )
{
}
}

class BClass extends AClass {
private int w ;
public void print()
{
System.out.println (" u + v + w = " + ( u + v + w ) ;
}
public BClass
{
super() :
w = 0 ;
}
public BClass ( int x , int y , int z )
{
Super( x , y ) ;
w = z ;
}
}




Solutions

Expert Solution

Firstly, there are some common syntax errors and spelling mistakes in the given program. We need to resolve them first.

Then, we tried to compile the program we got two errors as

This happens because members/attributes of a class which are declared by using private access specifier are not accessible outside that class.

Here, 'u' and 'v' data members of a class 'AClass' are declared with private access specifier and they are being accessed in 'BClass' class to perform operation. Hence, we are getting this error.

To solve this error, data members 'u' and 'v' are to be declared by using protected access specifier. Because members/attributes declared by using protected access specifier are only accessible within that class and derived class only.

Below is the code which solves the problems and errors we came up earlier

public class AClass
{
    protected int u ;
    protected int v ;
    public void print(){
    }
    public void set ( int x , int y )
    {
    }
    public AClass()
    {
    }
    public AClass ( int x , int y )
    {
    }
}

class BClass extends AClass 
{
    private int w ;
    public void print()
    {
    System.out.println (" u + v + w = " + ( u + v + w ) );
    }
    public BClass()
    {
    super() ;
    w = 0 ;
    }
    public BClass ( int x , int y , int z )
    {
    super( x , y ) ;
    w = z ;
    }
}


Following is the Driver class which shows the output of operation and working perform in above classes


public class Main
{
        public static void main(String[] args) {
                BClass b=new BClass(10,20,30);    //object of BClass
                b.print();
        }
}

OUTPUT

I hope that I have solved your query. If any problem occurs please mention it in comment section.

Thank you.


Related Solutions

Please use Java Eclipse and show code/output Please create a program that determines when a good...
Please use Java Eclipse and show code/output Please create a program that determines when a good day to go to the beach is. Please use the users input and its returning output. If the weather is 70 degree or greater, the program should say yes it is a good day to go If the weather is less than 70 degrees to say no the weather is not a good day to go
This code has to be in java (I code in eclipse). Also these instructions have to...
This code has to be in java (I code in eclipse). Also these instructions have to be followed exactly because if not my output won't match the expected out ( this will be uploaded on zybooks). Write a program that asks the user for their age in days. The program will compute the person's age in years (you can assume that all years have 365 days) and then prints one of the following messages: If the user is 1 year...
when i run the program on eclipse it gives me this error: Exception in thread "main"...
when i run the program on eclipse it gives me this error: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0    at SIM.main(SIM.java:12) how do I fix that ? (please fix it ) import java.util.*; import java.util.Scanner; import java.util.ArrayList; import java.io.File; import java.io.FileNotFoundException; import java.lang.Math; public class SIM{    public static void main(String[] args) throws FileNotFoundException {       int cacheSize = Integer.parseInt( args[1] ); int assoc = Integer.parseInt( args[2] ); int replacement = Integer.parseInt(...
C++ program. Please explain how the code resulted in the output. The code and output is...
C++ program. Please explain how the code resulted in the output. The code and output is listed below. Code: #include <iostream> #include <string> using namespace std; int f(int& a, int b) {    int tmp = a;    a = b;    if (tmp == 0) { cout << tmp << ' ' << a << ' ' << b << endl; }    b = tmp;    return b;    return a; } int main() {    int a...
I wrote this code and just realized I need to put it into at least 6...
I wrote this code and just realized I need to put it into at least 6 different functions and I don't know how. No specific ones but recommended is: Read Data, Calculate Installation Price, Calculate Subtotal, Calculate Total, Print -> 1) Print Measurements & 2) Print Charges. Can somebody help? #include <stdio.h> // Function Declarations int length, width, area, discount; int main () { // Local Declarations double price, cost, charge, laborCharge, installed, amtDiscount, subtotal, amtTax, total; const double tax...
Consider the game in Question 1(I wrote it at the end of this question. See below)....
Consider the game in Question 1(I wrote it at the end of this question. See below). Assume the only letter available are G, K and Q and that the game is played sequentially. a. Write down the game in its extensive form (assume Bill moves first) and find the Rollback equilibrium(a) of the game b. Specify the strategies of the two players c. Draw the game in its strategic form and find the Nash Equilibria d. Define a Subgame-Perfect Equilibrium...
I wrote this program to check a string is palindrome or not. but in both cases,...
I wrote this program to check a string is palindrome or not. but in both cases, it gives me palindrome. could someone help me with this program? it has an error I couldn't find. when I run the code and give a string, in both cases it gives me palindrome. for example if I give Pop it says it is a palindrome but if I give Salima, it also says palindrome. #include<string> #include <iostream> using namespace std; class PString:public string...
My code works in eclipse, but not in Zybooks. I keep getting this error. Exception in...
My code works in eclipse, but not in Zybooks. I keep getting this error. Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Scanner.throwFor(Scanner.java:937) at java.base/java.util.Scanner.next(Scanner.java:1478) at Main.main(Main.java:34) Your output Welcome to the food festival! Would you like to place an order? Expected output This test case should produce no output in java import java.util.Scanner; public class Main {    public static void display(String menu[])    {        for(int i=0; i<menu.length; i++)        {            System.out.println (i + " - " + menu[i]);...
Please create a Java Eclipse code and show output and explanation. MUST USE EXCEPTION! Step 1....
Please create a Java Eclipse code and show output and explanation. MUST USE EXCEPTION! Step 1. Ask users how much money was spent on an orange. Step 2. Then ask the user how many oranges they purchased Step 3. Lastly calculate the price for each orange purchased.
in python, sorry i thought i wrote it Write an interactive program that repeatedly asks the...
in python, sorry i thought i wrote it Write an interactive program that repeatedly asks the user to input a number until”Enter” is hit. Your program should create a file named “numbers.txt” where all the numbersare written one below the other, and the last line should display the sum of all the input, afterthe string “The sum of your numbers is ”.For example, if the user inputs 3, 5, 7, 10, -3, 5.2, then the file “numbers.txt” should contain: 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT