+ 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();

15th Apr 2017, 7:01 AM
Sam Shanmukh
Sam Shanmukh - avatar
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
15th Apr 2017, 7:10 AM
Shraddha
Shraddha - avatar
0
Hello Sam, Object Oriented Programing is exact0ly what you asking for. Take a deeper look to it.
11th May 2017, 11:02 PM
SeciuS