oop - Where is the object in this Java code -


i started learning oop using java. first code wrote :

class day1 {   public static void main(string args[]) {     system.out.println("java drives web");   } } 

when compile source file, .class file. when interpret @ command line, gives me desired result.

my question is: have not created object. have wrote class named day1. how able interpret it? oop object drawn classes. have not drawn class day1.

i confused in oop.

object oriented programming paradigm provides many concepts such inheritance, encapsulation, polymorphism etc. surprisingly these 3 major oops concept present in small simple hello world program also. trying prove that, please find below clarifications

1. use of inheritance concept in program

the object class, in java.lang package, sits @ top of class hierarchy tree. every class descendant, direct or indirect, of object class. every class use or write inherits instance methods of object.

so although did not extend class still day1 class implicitly extending object class , inherits methods of object class. so used inheritance concept here.

2. use of encapsulation concept in program

encapsulation in java or object oriented programming language concept enforce protecting variables, functions outside of class, in order better manage piece of code , having least impact or no impact on other parts of program due change in protected code.

encapsulation can achieved via access specifiers in java , you applied encapsulation concept in program. you declared main method access specifier public – main method can called jvm. made public permit call outside of application.

3. use of polymorphism concept in program

polymorphism in context of object-oriented programming, ability create variable, function, or object has more 1 form

system.out.println("java drives web"); 

here used println() method of printstream class. if go source code of printstream class, find ten methods present in class same name println different parameters.in short printstream class contains different overloaded method. so used compile time polymorphism (static binding or method overloading) here.

if talking object, got answer @madconan

answer @madconan

there many objects in code

  • class day1: class.
  • class object. args[]: object of type array. system:
  • the system object available everywhere. it's part of core api.
  • out: printwriter object instance member of system object.
  • "java drives web": string object.

just because never use new keyword doesn't mean aren't using objects.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -