non-static is a term to define a function or field that is bound to some object instance. Without an instance, non static fields cannot be accessed and non static methods cannot be invoked. Unlike static, non-static methods can be overridden (virtual).
Questions tagged [non-static]
525 questions
2
votes
2 answers
Referencing non-static variable from a static context
I was reading Kathy and Bert SCJP 1.6 and encountered the following code :
class Bar {
int barNum = 28;
}
class Foo {
Bar myBar = new Bar();
void changeIt(Bar myBar) {
myBar.barNum = 99;
System.out.println("myBar.barNum in changeIt is "…

Aman Grover
- 1,621
- 1
- 21
- 41
2
votes
5 answers
How is the Static method(main) able to grab hold of non static method(constructor) and execute it?
Seems like a very basic query but I was pondering how the static method main() below is able to execute a non static method(the constructor obviously) from it using the new keyword. Though I understand that new brings onto the table a few other…

Anirudh
- 2,286
- 4
- 38
- 64
2
votes
4 answers
Random number generator in a class method
This is part of a method inside of a class class. My goal is to generate a random number that number will be stored in a variable called iCell. After that, iCell will be used for the switch statement to change the character, cell. I am getting an…

user3471066
- 159
- 1
- 2
- 7
2
votes
2 answers
Call variable from other java class
I have this loginscreen class;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package program;
import…

Lacrymae
- 157
- 1
- 17
2
votes
1 answer
Matlab - Combining enumeration classes with non-static methods
I am attempting to combine an enumeration class with non-static methods in Matlab. I wish to create a 'LogEvent' class, which has the function 'log' which takes as an input argument an enumeration member (such as LogEvent.INFO, LogEvent.ERROR, or…

Charlie
- 469
- 4
- 15
2
votes
1 answer
Caesar Cipher in java don't recognize the methods
Hello i've a problem with my java program the caesar cipher:
it gives me this errors:
CifrarioCesare.java:27: error: non-static method cripta(String,int) cannot be referenced from a static context
c = cripta(s, spost);
…

Tiziano Loreti
- 33
- 4
2
votes
3 answers
Laravel Non-static method issue
Having the following Models:
news.php
class News extends Aware {
public static $table = 'noticia';
public static $key = 'idnoticia';
public static $timestamps = false;
public static $rules = array(
'titulo' => 'required',
…

Alex
- 7,538
- 23
- 84
- 152
2
votes
3 answers
non-static replacement for println
easy question is there an other function i can use instead of println, because i want to output a non-static variable to a file usig out.println();
This is my code:
import java.io.*;
public class main {
String outputString ="Math.sqrt(25);"…

Neobonde
- 85
- 2
- 7
2
votes
1 answer
cant access class variable from class function
i created a header Persona.h and in Persona.cc i am initializing all the variables and functions of the class, why can't i access a variable from Persona.cc?
Persona.h
#ifndef STD_LIB_H
#include
#endif
#ifndef STD_LIB_H
#include…

DomeWTF
- 2,342
- 4
- 33
- 46
2
votes
3 answers
Illegal call of non-static member function
I wish to make a calculator that can calculate numbers of almost any length.
The first function that I needed is one that converts a string into a linked list and then returns a pointer to the head of the list.
However, when compiling I am faced…

Avgar
- 21
- 1
- 1
- 4
2
votes
4 answers
Misunderstanding in Java
I'm trying the static and non-static methods and fields.
I tried to compile this:
class main{
public int a=10;
static int b=0;
public static void main(String[] args){
b+=1; //here i can do anything with static fields.
…
user1462183
2
votes
1 answer
Working example of accessing non-static member from static method
I was studying ns-3 tutorial. I cannot understand the following code snippet:
class MyObject : public Object
{
public:
static TypeId GetTypeId (void)
{
static TypeId tid = TypeId ("MyObject")
.SetParent (Object::GetTypeId ())
…

user1558573
- 385
- 3
- 7
2
votes
2 answers
Access static variable in non-static method + Inheritance
I have the following stucture
class Foo
{
public static $a = "parent";
public static function Load()
{
return static::$a;
}
public function Update()
{
return self::$a;
}
}
class Bar extends Foo
{
…

Artmann
- 130
- 3
- 14
2
votes
5 answers
Static And Non Static Method Intercall In Java
I am clearing my concepts on Java. My knowledge about Java is on far begineer side, so kindly bear with me.
I am trying to understand static method and non static method intercalls. I know --
Static method can call another static method simply by…

Vishal
- 279
- 3
- 8
- 18
2
votes
5 answers
Android non-static string to Static string error
I am building a database class in android which gathers String non-static data from the getIntent().getStringExtra(name) function.
The value of this i am putting in a simple string variable (Non-Static).
When im trying to use it inside a static…

rel-s
- 6,108
- 11
- 38
- 50