• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

A bunch of questions on different topics

 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Guys, how can you explain the following from the point of view of language grammar and internal logic.

(1) Why these do NOT compile? Can I use the super keyword in Type declaration?




(2) ref. to non-static from static context error arises... or not arises. From this I dont understand, whether method in static class is considered to be a static context or not?


(3) Just nice observation. Any comments, additions?


(4) Why cant I run the go() function? What is the meaning of my declaration of go()? It works only if there is a go() function in the Enum itself.


(5) Can anyone advice a FREE mock exam with the same level of complexity as ExamLab and Master Exams?
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do let us know the source of these questions.

You can find more mock exams here -> SCJPMockTests
 
Sheriff
Posts: 7410
1423
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepak Bala wrote:You can find more mock exams here -> SCJPMockTests


...and there are couple of mock exams in Deepak's signature.
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For your first question, what you need to understand is the difference between a type variable (JLS 4.4. p. 49) and a type argument (JLS 4.5.1. p.52).

If you read the JLS, you will notice that it says that type variables are used on generic class and interface declarations and in generic method declarations. And this type of declarations only accept "extends" clause, and not the "super". For instance, your method could be declare as follows:

Now, type argument is a different thing and they are allowed to use wildcards. Your confusion is based on the fact that one of the wildcards is named also "extends", a clear example of Java language polymorphism. In this case, the clause is used for two different things.

As its name suggest, you can use this to declare the expected type of arguments. For instance, you can say:

Or in a method declaration.

You can combine both, like this:

Later I will try to reply to your other questions, because this takes time.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your second question is a bit simpler. The class named A3 has access to the g field because it inherited it from its parent class (named Parent), whereas the classes A1 and A2 do not inherit from Parent and therefore do not have access to it.

You could also change your static inner classes to inner classes to have access to the variables declared in the outer class. Like this.



Regarding your third example I have not comments. I think it is fairly obvious what is the right syntax for this.

Regarding your final question about enums. The JLS 8.9 about Enums, page 249 states that the optional class body of a en enum constant implicitly defines an anonymous inner class declaration. If you compile this code and review the class files generated by the compiler you will validate that this is true.

What you are doing there is equivalent to this:



How do you invoke the "go" method in y? The answer is: it is not possible.

You can, however, do somewhat like this:




Now you can invoke the go method.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic