0

I am a rookie programmer in Java. I want "aaa" to be printed in main and displayed "123". In C++ if use pointer in the define arguement (e.g. char * a), and will return the value to the variable which is passed to the function.

How do I make this happen in Java? and I don't want to have a return type of String. (I need to use the argument to print). It shows null" for now.. If anyone could help I will appreciate!

public class DeppDemo {
    private String aaa;

    public void abc(String a) {
        a = "123";
    }

    public static void main(String[] args) {
        DeppDemo demo = new DeppDemo();
        demo.abc(demo.aaa);
        System.out.println(demo.aaa);
    }
}
Chris Martin
  • 30,334
  • 10
  • 78
  • 137
Ron
  • 1
  • 2
  • 1
    You are not putting a value in `aaa` so it will stay `null`. I suggest following the [official tutorials](https://docs.oracle.com/javase/tutorial/) or buying a good Java book to learn the basics. – RealSkeptic Aug 16 '15 at 07:27
  • you are assigning value a not aaa , public void abc(String a) { aaa = "123"; } – Panther Aug 16 '15 at 07:28
  • I want the variable aaa to be returned the certain string which is assigned to the argument in the function abc... – Ron Aug 16 '15 at 07:38
  • To indent a code block on Stack Overflow, highlight the code and press ctrl+K. – Chris Martin Aug 16 '15 at 07:39

0 Answers0