PROBLEM IN EXECUTION

Ads
 

PROBLEM IN EXECUTION

class R { private int x; private int y;

  void getdata(int x1,int x2)
     {
          x=x1;
          y=y1;
     }
  void displaydata()
     {
          system.out.println(x+"\t"+y);
     }
}

class J { public static void main(String args[]) { R c1,c2; c1 = new R(); c2 = new R();

    c1.getdata(10,20);
    c2.getdata(30,40);
    c1.displaydata();
    c2.displaydata();
    System.out.println(c1.x+"\t"+c1.y);
    System.out.println(c2.x+"\t"+c2.y);
    } 
    }

//THE PROGRAM IS SHOWING 6 ERRORS 1.PACKAGE SYSTEM DOES NOT EXIT 2.X HAS PRIVATE ACCESS IN R 3.Y HAS PRIVATE ACCESS IN R

View Answers

February 21, 2011 at 11:21 AM

Java Program

Private modifier does not allow to access the private variable, method of another class.

class R {
     int x;
     int y;

  void getdata(int x1,int y1)
     {
          x=x1;
          y=y1;
     }
  void displaydata()
     {
          System.out.println(x+"\t"+y);
     }
}
class J {
    public static void main(String args[]) {
    R c1,c2;
    c1 = new R();
    c2 = new R();

    c1.getdata(10,20);
    c2.getdata(30,40);
    c1.displaydata();
    c2.displaydata();
    System.out.println(c1.x+"\t"+c1.y);
    System.out.println(c2.x+"\t"+c2.y);
    } 
    }

Ads









Related Tutorials/Questions & Answers:
PROBLEM IN EXECUTION
PROBLEM IN EXECUTION  class R { private int x; private int y; void getdata(int x1,int x2) { x=x1; y=y1; } void displaydata() { system.out.println(x+"\t"+y
problem at the time of execution - JSP-Servlet
problem at the time of execution  when i was running web applications the exception i.e 404 resource is not available what it means and where it occures what is the solution   Hi Friend, This error occurs when
Advertisements
execution
execution
execution
execution of a jdbc program
execution of a jdbc program  how to execute a servlet program that..uses a jdbc driver (i.e. using mysql-connector -java )to connect to mysql in windows *PLS provid the execution steps in detail THANK YOU
Version of com.automationrockstars>execution dependency
List of Version of com.automationrockstars>execution dependency
to know execution time
to know execution time  Hai this is sravanthi Is there any possibility to know the execution time of an SQL in its order to execute... to know the execution time for where,having and group by separately.If
problem in onlinetest...
problem in onlinetest...  hi, my code getting the problem is ,when user leave a question then the server puts error... pls help me
Struts-problem With DispatchAction Class
Struts-problem With DispatchAction Class  hi this is Mahesh...i'm...: Servlet execution threw an exception root cause java.lang.NoClassDefFoundError: org/apache/struts/actions/DispatchAction Can any one help me with this problem
execution of java program
execution of java program  wat are the steps for the execution of the servlet-jdbc program on tomcat 5.5 server.. PlS provide..the execution steps in detail..including the setting of classpath in DOS for mysql-connector-java. i
javascript problem
javascript problem  hi guys My problem is that I am using radio button for yes or no but i want to do that if I press yes button then enter... enter please help me this problem
ModuleNotFoundError: No module named 'execution-asserts'
ModuleNotFoundError: No module named 'execution-asserts'  Hi, My... named 'execution-asserts' How to remove the ModuleNotFoundError: No module named 'execution-asserts' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'execution-pipeline'
ModuleNotFoundError: No module named 'execution-pipeline'  Hi, My... named 'execution-pipeline' How to remove the ModuleNotFoundError: No module named 'execution-pipeline' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'Execution-Time'
ModuleNotFoundError: No module named 'Execution-Time'  Hi, My... named 'Execution-Time' How to remove the ModuleNotFoundError: No module named 'Execution-Time' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'execution-trace'
ModuleNotFoundError: No module named 'execution-trace'  Hi, My... named 'execution-trace' How to remove the ModuleNotFoundError: No module named 'execution-trace' error? Thanks   Hi, In your python
Version of com.twitter>execution-tutorial_2.12 dependency
List of Version of com.twitter>execution-tutorial_2.12 dependency
Version of com.twitter>execution-tutorial_2.10 dependency
List of Version of com.twitter>execution-tutorial_2.10 dependency
Version of com.twitter>execution-tutorial_2.11 dependency
List of Version of com.twitter>execution-tutorial_2.11 dependency
problem on strings
problem on strings  in string1 "123456 ABC DEF...",IN string2 "raveen". iwant to add string2 after 123456 in the first string based on index number.i need logic for this with out using StringBuffer concept. Thanks in advanace
Problem with loginbean.jsp
Problem with loginbean.jsp  http://www.roseindia.net/jsp/loginbean.shtml - I am getting an error in loginbean.jsp.There is some error regarding .What is hello in this? Also in this example how
compilation problem
compilation problem  struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation problem that package open symphony doesnot... havenot set the build path.if this is the problem then tell me how to set
compilation problem
compilation problem  struts 2.0 : i have included all 5 jars in lib folder,but its giving compilation problem that package open symphony doesnot... havenot set the build path.if this is the problem then tell me how to set
Problem with cookies
Problem with cookies  Hello All, i need jsp code for RememberMe module of login. i am facing problem with cookies. so please if any one could guide me please help and provide mme the exact code.   Please visit
problem with package
problem with package  Dear sir, i have created one java file with package com.net; and i compiled the program.it showing the .class file in " net" folder.The problem is i want to use that .class file in some other
Oracle9i Problem
Oracle9i Problem  Hi I have a problem in Oracle9i .I have... the table what i created .But after closing the SQL+ ,the problem started.When i... .....;.it is saying no rows are selected.Why the problem arised in not getting the data that i
Execution of Multiple Threads in Java
Execution of Multiple Threads in Java  Can anyone tell me how multiple threads get executed in java??I mean to say that after having called the start method,the run is also invoked, right??Now in my main method if I want
problem with session.invalidate()
problem with session.invalidate()  i stuck by a line with "session.invalidate()", after user logout also by pressing the back button of the browser user is still able to navigate to his home page and able to view the session
JScrollBar Problem...
JScrollBar Problem...  Hello Sir/mam, Can i know how to use JScrollBar to JFrame without adding any JPanel to it.. i want to add JScrollBar Directly to JFrame... Please Provide me Simple Example so i can understand
problem on php
problem on php   l have five tables and build them as forms and link between them php and database and i want to build query between them plz help me soon   PHP MySQL Tutorials
URL problem
URL problem  Hi. I have created a webpage for my project website. in that i have used frameset to split the page. Now if i click any link in the page its navigating to the another page. but the problem is here in the url its

Ads