C:\Practice Test Code>javac Xy144.java
Note: Xy144.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
C:\Practice Test Code>javac -Xlint:unchecked Xy144.java
Xy144.java:15: warning: [unchecked] unchecked call to add(E) as a member of the
raw type ArrayList
ref.add("ABC ");
^
where E is a type-variable:
E extends Object declared in class ArrayList
Xy144.java:16: warning: [unchecked] unchecked call to add(E) as a member of the
raw type ArrayList
ref.add("DEF ");
^
where E is a type-variable:
E extends Object declared in class ArrayList
Xy144.java:17: warning: [unchecked] unchecked call to add(E) as a member of the
raw type ArrayList
ref.add("GHI");
^
where E is a type-variable:
E extends Object declared in class ArrayList
3 warnings
John Stuart wrote:So, I've just started learning Java and have some difficulties understanding basic Java programming terms. These terms are:
1. Class
2. Object
3. Methods
4. Instance
5. Instance Variable
6. Others (e.g., member variable, class variable, member methods, instance methods, and many more)
enrique davis wrote:I'd like to add to this topic
I'm studying for the OCA and I'm at chapter 4 but I don't remember what was in chapter 1 and 2
I'm not sure if I'll ever be able to pass this exam
My problem is to find time to study, I only study one or 2 nights a week.
Can someone suggest a working study strategy
Thanks
Henry Wong wrote:
Travis Roberts wrote:
aObj.m(bObj);
Does the reference variable aObj not matter?
What do you mean by "not matter"? As already mentioned in a previous post, the compiler uses the type to determine the method to call. And since it is a class A instance, it will call the m() method that takes a class A instance, as that is the only method that matches.
Henry
Henry Wong wrote:
Travis Roberts wrote:
And this line of code is even more confusing because I have called the method inside class A and passed it a class B object. Class A does not inherit from B. In this case I expected the compiler to blow up.
I am utterly confused.
Class B extends class A... so doesn't that means that an instance of class B IS-A instance of class A? An instance of B is supposed to work everywhere that expects an A, so why should it "blow up"?
Henry
Jeanne Boyarsky wrote:They are just trying to show you can. It's rare to actually need to.
One reason is if you don't write all the code yourself. Maybe someone gives you a list of Objects and you know they are of a certain type.
There's also an instanceof operator so you can check the type before casting. For example, you give me a list of objects. I want to do math if they happen to be numbers of just print them otherwise. I can use instanceof to check the type. if it is a Number, I can cast it and then use methods available on number.
ps - You aren't required to post a link to the book. It's helpful though in case someone has a question on the context.