How to instantiate an object in java?
问题 I'm new in programming and I would like to know where did I go wrong in instantiating an object. Below is the code: public class Testing{ private int Sample(int c) { int a = 1; int b = 2; c = a + b; return c; } public static void main(String []args) { Sample myTest = new Sample(); System.out.println(c); } } 回答1: There is no Sample class in your code . The one which you have declared is a private method . // private method which takes an int as parameter and returns another int private int