+ 4
Can we create a variable in java using the class name and without datatype..
i've in some programs creating a variable that calls methods instead of carrying a value using class name like : if my class name is A then A a; a.method();
2 Answers
+ 5
class myClass{
public int myInt; //this is a variable in your class
public void myMethod{ //this is a method in your class
System.out.print(myInt);
}
}
myClass a=new myClass(); //create an object of a.myInt = 1;//access class variable
a.myMethod(); //access class method
0
Hello Sam, Object Oriented Programing is exact0ly what you asking for. Take a deeper look to it.