English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have two classes. One class one class Note has a method named private String getWord() and it returns word. I want to use that in another class Notebook, what can i do to call that method and use that note in that other class Notebook?

2006-10-18 07:06:54 · 6 answers · asked by dan the man 2 in Computers & Internet Programming & Design

6 answers

If your method is private, there is no way you can access it from another class... It is visible only in the class in which is declared (you cannot even call the method from an instance(reference) of this class, only you can call this method inside another class method). First you need to change the method to public so it can be visible from derived class or directly from an instance(reference) of this class. If you intend to call this method without using an object of the class Note, you need also to declare the method static so the syntax will be "public static String getWord()". (Excuse the instance(reference) additional comments... cannot help it ...C++ leaves tracks ...:))

2006-10-18 08:10:13 · answer #1 · answered by None A 3 · 1 0

I think you import the note class at the very top of the program i forget the syntaxt
IMPORT note.waht ever the extension
u might have to change it to publi maybe

or notebook can inherit the class note I have no idea how to do it in java

2006-10-18 07:51:13 · answer #2 · answered by tru_story 4 · 0 1

"private" means, that only the declaring class can access it.
If you want to be able to call it from any other class, make it "public", or if you only want subclasses of this class (plus all the classes that belong to the same package) to access it , make it "protected", or just remove the modifier completely - that will make it accessible to all classes in the same package, but not any others.

2006-10-18 07:59:14 · answer #3 · answered by n0body 4 · 1 0

it quite is slightly unusual which you're able to have a considerable technique in all your instructions, yet who am I to question your layout. If all of the instructions declare a considerable like here: public static void considerable( String[] args ) then your purchase technique could be enforce as follows: public classification Menu { public static void considerable( String[] args ) { // Get the instant from someplace String instant = ...; if( instant.equals( "a million" ) ) { purchase.considerable( args ); } else { sell.considerable( args ); } } }

2016-11-23 17:52:50 · answer #4 · answered by ? 4 · 0 0

create the object of that class, and access the method via that object.

2006-10-19 21:37:39 · answer #5 · answered by Anand 3 · 0 0

sophisticated subject. look into at yahoo. just that can assist!

2014-11-15 19:59:45 · answer #6 · answered by Anonymous · 0 0

fedest.com, questions and answers