Paul Clapham wrote:
The getContentPane() method returns a reference to some object. So what is calling add(button)? That object is.
Randy Tong wrote:
Hari Nagarjuna wrote:What is happening in System. out. println()??
dot(s) used to separate class name, field and method.
In this case, out is a class variable of type PrintStream which declared in the System class, while println methods is in class PrintStream.
So we need to use System.out.println to print something out in console.
Paul Clapham wrote:
Hari Nagarjuna wrote:Yes. I understand that it is a static method.
But why are we assigning a method to a object reference variable of calendar(c)?
Can't we only assign objects(Objects may be of its subclasses in case of using polymorphism) to object reference variables??
Oh right, it's that question. Yes, you have a reference variable of type Calendar. And you're assigning to that variable a reference to some object. So the object must be assignable to a variable of type Calendar. But that doesn't mean it has to be an object of the Calendar class. It can be an object of some non-abstract subclass of Calendar... which is what it is.
Try writing another line of code which tells you what class that object actually belongs to.
Paul Clapham wrote:It calls a static method from the Calendar class.
True, Calendar is an abstract class and you can't create an object of the Calendar class, but as you know by now, a static method doesn't need a method for it to be called.
You can tell it's a static method because the name of the method is prefixed by the name of the class.
Junilu Lacar wrote:No, an interface does NOT inherit from Object, or more correctly, it is not a subtype of the Object class. Think of an interface as a description of some kind of capability. You don't instantiate interfaces; you instantiate objects.
Try running this code:
Stephan van Hulst wrote:
Brecht Geeraerts wrote:All interface methods are implicitly public (if I am not mistaken)
If you don't use an access modifier the method will be public. Since Java 9, you can also declare private methods in an interface which like default and static methods can not be abstract.
Campbell Ritchie wrote:Can you write int as a type? I thought you can only use the number on the right of the assignment operator:
Les Morgan wrote:. . . If we type int what we have created is a reference that will point to 3 integers, but it is still only the variable that will reference the ints, we have not constructed an array yet--just a referencing scheme. . . .That is called an array initialiser. Unlike writing new int, which creates an array filled with 0s/nulls/falses, an initialiser creates an array filled with the actual values desired. Code like...both declares the reference and creates the array object in one line.
. . . you typed in a literal array/collection of ints. . . .
Les Morgan wrote:Hari,
I am not sure I understand completely what you are asking, but let me see if I am getting a piece of what you are saying.
When we "create an array" in Java and many other languages, I think what you are referring to is the left side of the expression: int in the case we wish to build an integer array. When we type int, there is no array created, but instead what we have made is a reference that will be set to reference an array object. If we type int what we have created is a reference that will point to 3 integers, but it is still only the variable that will reference the ints, we have not constructed an array yet--just a referencing scheme.