-5

For example if we wrote one program like

class sum{ 
    public static void main(String []k){
        int a=10,b=30,c; c=a+b; 
        System.out.println("op is"+c);
    }
}

in this program where is object?

Popeye
  • 11,839
  • 9
  • 58
  • 91
Anilkumar
  • 47
  • 1
  • 8
  • 1
    `System` is a `Class` (which extends from `Object`), `System.out` is an `Object`, you class extends from `Object`, all objects inherit from `Object` if you don't otherwise implicitly extend from another `Object`. `Object` also defines `hashcode` and `equals` (and other base methods) which are all very useful – MadProgrammer Feb 12 '16 at 09:02
  • 1
    k is an object (a string array); System.out is an object (a PrintStream); "op is" is an object (a string literal)... – Andy Turner Feb 12 '16 at 09:03
  • 2
    @MadProgrammer `System` is a class, not an object. – ApproachingDarknessFish Feb 12 '16 at 09:03
  • 1
    @ApproachingDarknessFish And I thought I was nit picky :P – MadProgrammer Feb 12 '16 at 09:04
  • OBJECT SYNTAX IS LIKE FOR EX:class objname=new classname() but in the above format we cannot use this type of syntax then where is object – Anilkumar Feb 12 '16 at 09:07

3 Answers3

1

also when we run any java program there is one object internally created. object of java.lang.Class.

suraj
  • 11
  • 6
0

Here you have multiple objects !

When you will run your program, sum is the first one. You also have an array of strings String []k

System is also an object with a field out which is of type `PrintStream``

"op is"+c is also an object of type String

PS : note that a, b and c are primitive types. More about data types in java : https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

Louis F.
  • 2,018
  • 19
  • 22
  • in memory (RAM) ! Have a look at : https://en.wikipedia.org/wiki/Java_memory_model – Louis F. Feb 12 '16 at 09:08
  • 1
    It loads the class into the memory. That doesn't mean that `sum` will be instantiated. Why do you think `main` is `static`? So it doesn't need to create an instance of the surrounding class (which wouldn't work if there aren't any non-parameterized constructors). – Tom Feb 12 '16 at 09:11
  • Actually you raise a good point : http://stackoverflow.com/questions/146576/why-is-the-java-main-method-static – Louis F. Feb 12 '16 at 09:14
  • how we see java libraries using cmd prompt – Anilkumar Feb 12 '16 at 09:40
0

"op is" is a String object k is an array of String objects