Once my teacher was taking my viva and she asked me to explain the below line.

Scanner sc = new Scanner(System.in)

I told her that this creates a newScanner instance which points to the input stream passed as argument
She shouted at me and said that I am wrong.
She explained to me that this line creates a new object not an instance

  • 39
    Shouldn't wk73 be about best experiences? If that was your best experience, you have a sad life.
  • 6
    @CWins some people just like to suffer.
  • 3
    RiP. Wtf. At least my teacher knows what an instance is. But sadly we are only learning Java in class, instead of c++ (which I already know quite well). It confuses me so much if a parameter/member var or whatever is a pointer, reference or just whatever. Like... In c++ I can decide whether a function with parameter x can access the original var x or receives a completely other var (same val). But in java class I'm sooooo confused
  • 2
    @CWins Interacting with teachers is very boring.. but I always wonder how they became an engineering teacher
  • 1
    @sauravnk30 I'm triggering my "Java Teacher" every lesson 😂
  • 0
    Look up "call by reference" and "call by value". It might seem confusing but it's actually more simple than in C++ once you got it.

    It's good that you learned C++ because knowing about how pointers and managing memory works is of good value even when using other languages.

    I also think that it's good that you're now forced to learn java. Could as well be C#. It's a little different than C++, but once you got used to it, you will see the value and why these languages are sometimes the better tool.
  • 1
    @CWins I know that in java arrays get passed by ref and normal vars as value. But still its confusing since I'm working in c++ most of my time. I'll have a look at how exactly its working in java. Or I just ask my teacher. I mean... That's what he gets paid for
  • 0
    Did your teacher study engineering?
    In a lot of schools, especially those without a technical focus, the dev-teachers are often not people who studied it or worked in the field but rather the best they got, which might mean he studied biology in 1985 and installed Doom on the library computer in 1995 which made him the "technology expert" in that school.
  • 0
    You don't pass arrays, you pass a reference to the array by value. ;-)
  • 0
    @lukegv lol I think I know how it works now😝thx
Add Comment