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

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...
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]);...
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...
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...
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.
I need to write a java program (in eclipse) that will read my text file and...
I need to write a java program (in eclipse) that will read my text file and replace specific placeholders with information provided in a second text file. For this assignment I am given a text file and I must replace <N>, <A>, <G>, with the information in the second file. For example the information can be John 22 male, and the template will then be modified and saved into a new file or files (because there will be multiple entries...
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...
Can you please see what I have done wrong with my program code and explain, This...
Can you please see what I have done wrong with my program code and explain, This python program is a guess my number program. I can not figure out what I have done wrong. When you enter a letter into the program, its supposed to say "Numbers Only" as a response. I can not seem to figure it out.. instead of an error message. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if...
I just wrote Python code to solve this problem: Write a generator that will return a...
I just wrote Python code to solve this problem: Write a generator that will return a sequence of month names. Thus gen = next_month('October') creates a generator that generates the strings 'November', 'December', 'January' and so on. If the caller supplies an illegal month name, your function should raise a ValueError exception with text explaining the problem. Here is my code: month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] def next_month(name: str) -> str:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT