sekhar kiran wrote:the basic thing whenever calling method should be semicolon,am i right
Jeff Verdegan wrote:I already answered that question twice. I'm not answering it again.
Jeff Verdegan wrote:I already did for some of them. I'm not going to repeat myself. For the others, I'm going to leave that as an exercise for you.
If you want to learn, you need to be a more active participant in your own education, rather than just sitting back helplessly, waiting for people to shove information down your throat.
Jeff Verdegan wrote:The error message is telling you what the problem is. If you don't understand the error and you want somebody here to help you with it, then copy/paste the exact, complete error message here, and indicate clearly which line is causing it.
sekhar kiran wrote:
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
sekhar kiran wrote:
Jeff Verdegan wrote:The error message is telling you what the problem is. If you don't understand the error and you want somebody here to help you with it, then copy/paste the exact, complete error message here, and indicate clearly which line is causing it.
methodcall.java:13
cannot find symbol
symbol : method a(int,int)
location: class methodcall
a(5,3);
fred rosenberger wrote:
So i'm coming to this thread a little late, and don't plan on reading the other 100+ posts...but...
This error looks fairly straightforward.
Do you have a method named "a" that takes two integer types in this class?
sekhar kiran wrote:
fred rosenberger wrote:
So i'm coming to this thread a little late, and don't plan on reading the other 100+ posts...but...
This error looks fairly straightforward.
Do you have a method named "a" that takes two integer types in this class?
yeah i declared method a see below
symbol : method a(int,int)
location: class methodcall
Jeff Verdegan wrote:Look at this part of the error message again:
symbol : method a(int,int)
location: class methodcall
It says that the method a(int,int) does not exist in the class methodcall.
You have to hae a reference to an instance of methodDeclaration in order to call its a() method, just like you have to have an instance of PrintStream (such as the instance refererred to by System.out) in order to call its println() method.
sekhar kiran wrote:actually i need to know how the program exection process that is java does not execute line by line process,whenever we run the program it goes to main method after that how the proecess will goes
Jeff Verdegan wrote:
sekhar kiran wrote:actually i need to know how the program exection process that is java does not execute line by line process,whenever we run the program it goes to main method after that how the proecess will goes
It enters main, and it executes whatever is in main, in order, except as affected by branching (if, switch/case), looping (for, while, do/while), constructors, or method calls. You can see that in your own program.
sekhar kiran wrote:can you tell me the order for my previous program by mention the numbers how it execute program,it is helpful to me and easily understand
Jeff Verdegan wrote:You can't put statements just any old place. They have to go inside a method, constructor, static initializer block, or instance initializer block.
The place where you're trying to put that println() is not a line that gets executed.
No, there is no such value as a in your code at all. There is a class with the poorly chosen name a, but no value a.sekhar kiran wrote: . . . here a is local variable or instance variable? . . .
Campbell Ritchie wrote:
No, there is no such value as a in your code at all. There is a class with the poorly chosen name a, but no value a.sekhar kiran wrote: . . . here a is local variable or instance variable? . . .
Campbell Ritchie wrote:You will probably find something about default values in this section of the Java™ Tutorials.
~ Mansukh
Mansukhdeep Thind wrote:Here b is a local variable as it is declared locally inside a method. You are not allowed to use a local variable without initializing it like you have done. Hence, the compiler is complaining.
~ Mansukh
Mansukhdeep Thind wrote:Please read this tutorial. Try and understand the different types of Java variables. If you have a doubt, revert back.
sekhar kiran wrote:i think here a is an instance variable,but how to execute the program and print default value of instance variable...
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
sekhar kiran wrote:
Mansukhdeep Thind wrote:Please read this tutorial. Try and understand the different types of Java variables. If you have a doubt, revert back.
i think here a is an instance variable,but how to execute the program and print default value of instance variable
l.java:4: <identifier> expected
System.out.println(a);
^
l.java:4: <identifier> expected
System.out.println(a);
^
2 errors
~ Mansukh
class l
{
int a;
System.out.println(a);
public static void main(String args[])
{
}
Campbell Ritchie wrote:That will not compile because you have a statement outside any methods.
And don’t go back and correct posts after they have been replied to. That makes the replies look like nonsense.
sekhar wrote: but if i provide static variable i can able to get default value,here below program which gives output 0 which is default value for static variable, in the same way how to get instance variable default value
~ Mansukh
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
sekhar kiran wrote:but if i provide static variable i can able to get default value
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
fred rosenberger wrote:These two examples aren't equivalent:
or rather...there are TWO differences. In the first example, you have a member variable and an executable statement outside a method.
In the second, you have a static member variable, and NO executable outside a method.
The best way to experiment is to change exactly ONE thing...either make 'a' static, OR move the println statement. If you do two (or more) things, you don't know what caused what.
Mansukhdeep Thind wrote:
sekhar wrote: but if i provide static variable i can able to get default value,here below program which gives output 0 which is default value for static variable, in the same way how to get instance variable default value
No. That is not correct. static is a keyword in java which marks that particular member as belonging to a class rather than an instance. And the 0 that you see is because it is an int type, which is by default initialized to 0. I feel I am spoon feeding you. You need to devote more time to self study.
sekhar kiran wrote:let me confirm first if we doesnot provide any values to instance variable will they assign default value automatically
like int ->0,String->null,boolean->false,char->null,byte->0 ,is it right or wrong,
sekhar kiran wrote:
upto my knowledge which iam studied about java,static variables and instance variable are different,static int a means it refers to static variables,int a means it is instance variable,
i know static is keyword in java which is also refere as class variables it can initialized first and only once
,we dont want to create objects
Jeff Verdegan wrote:
sekhar kiran wrote:let me confirm first if we doesnot provide any values to instance variable will they assign default value automatically
Default values are given to both instance variables (non-static member variables) and class variables (static member variables). This happens whether we initialize them or not.
like int ->0,String->null,boolean->false,char->null,byte->0 ,is it right or wrong,
Close. More specifically:
byte: 0
short: 0
char: 0 (not null--char is a primitive so it cannot be null)
int: 0
long: 0
float: 0.0
double: 0.0
boolean: false
all references: null
Jeff Verdegan wrote:That's not why we use static methods and member variables. We don't try to avoid creating objects. The whole point of an object-oriented language is that a lot of what you want to express is accomplished by using--surprise!--objects.
So when we use static members, it's not because we're trying to avoid creating an object; it's just that an object doesn't make design sense in that situation.
sekhar kiran wrote:
previously i know about default values for primitive data types,but i studied char has null see char 0 to 2^7 –1 -> null character (or) ‘\u 0000’ is this wrong?
ok practically how to get default values in program without initialize any values
yeah ok,i mean what iam trying to say means static variable can be accesed before any object is created,at the starting of program static variable and static block will be initialize once
,what happens if we give final to static
Jeff Verdegan wrote:The "null character" is completely different from Java's null reference value. "Null character" is just a name given to the char with value 0. It's still a simple numeric primitive, and it has nothing to do with the null value that's used for references.
Jeff Verdegan wrote:
I don't understand the question. Member variables are always given their default values before we get to touch them. If we don't initialize them explicitly at declaration, they retain those values until we set a value elsewhere.
Jeff Verdegan wrote:
Static variables are initialized and static blocks are executed when the class is initialized. Since classes are loaded on-demand in Java, and not all at the start of the program, most statics will not be initialized at startup. They won't even exist.
so it means its values doesnot changeJeff Verdegan wrote:
Exactly the same thing as if you make any other varialbe final: It can only have its value set once.
Additionally, final static variables have the requirement that they must be initialized at declaration or in a static initializer block in the class that declares them.
sekhar kiran wrote:even static variable also get default values if we donot specify anything to that variable,so the same way how can we get instance variable default value,if i provide int a in 6th line it will be treated as local variable ,so for local variable we have specify values otherwise it will compile time error
so most static will no be initialise at start up and wont even exist means then how it can be initialized and why it is not initialising
sekhar kiran wrote:even static variable also get default values if we donot specify anything to that variable,so the same way how can we get instance variable default value,if i provide int a in 6th line it will be treated as local variable ,so for local variable we have specify values otherwise it will compile time error
sekhar kiran wrote:even static variable also get default values if we donot specify anything to that variable,so the same way how can we get instance variable default value,if i provide int a in 6th line it will be treated as local variable ,so for local variable we have specify values otherwise it will compile time error
Jeff Verdegan wrote:Correct. Local variables do not have default values. We have to explicitly assign a value to them before we can read them.
sekhar kiran wrote:so most static will no be initialise at start up and wont even exist means then how it can be initialized and why it is not initialising
can you give any example which understands clearlyJeff Verdegan wrote:They come into existence and get initialized when the class that declares them is loaded, which in turn happens the first time that class is used.
sekhar kiran wrote:then how to print default values of instance variable if we donot provide values
sekhar kiran wrote:so most static will no be initialise at start up and wont even exist means then how it can be initialized and why it is not initialising
can you give any example which understands clearlyJeff Verdegan wrote:They come into existence and get initialized when the class that declares them is loaded, which in turn happens the first time that class is used.
Evildoers! Eat my justice! And this tiny ad's justice too!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|