File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Abstract class?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Abstract class??" Watch "Abstract class??" New topic
Author

Abstract class??

Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

The below one is from here

Select 2 correct options

1. The class TestClass cannot be declared abstract
2. The variable j cannot be declared transient
3. The variable k cannot be declared synchronized
4. The constructor TestClass( ) cannot be declared final
5. The method f( ) cannot be declared static


Answer given as 3 and 5, 3 is ok but how come 5??


SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Manju Devarla
Ranch Hand

Joined: Dec 14, 2006
Posts: 85
Becuase Interface methods and abstract class methods cant be static
Ahmed Khan Mohammed
Greenhorn

Joined: Dec 07, 2006
Posts: 13
Thats because the variable j is non static and cannot be accessed from a static context.

Followup to the comment :
An abstract class can contain static methods.
ashni Prakash
Ranch Hand

Joined: Dec 05, 2006
Posts: 50
In the above code given by jothi how come the constructor has return type.As per my knowledge constructors doesnt have any return type not even void.Can anyone clear my doubt please?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
It is not a constructor: it is a method that happens to have the same name as the class.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
ashni Prakash
Ranch Hand

Joined: Dec 05, 2006
Posts: 50
But in the 4th option they have said its a constructor.The below link has given differences between constructors and methods which says methods cant have same name as class.

http://www.javaworld.com/javaworld/jw-10-2000/jw-1013-constructors.html
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Try this:

Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
The below link has given differences between constructors and methods which says methods cant have same name as class.
Actuallly the article doesn't say that at all.
Constructors have the same name as their class; by convention, methods use names other than the class name.
Emphasis mine.


Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
ashni Prakash
Ranch Hand

Joined: Dec 05, 2006
Posts: 50
hi ranchers,


I executed the code successfully.As per my understanding by java convention it is not advisable to use classname as method name but it wont throw errors if we use it.
[ December 19, 2006: Message edited by: nike sama ]
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Thanks ranchers. I didn't notice the use of non-static variable from a static context when I was answering this question. Thanks all for the participation.
Pratap koritala
Ranch Hand

Joined: Sep 27, 2006
Posts: 252
not worth to be asked for real scjp
[ December 19, 2006: Message edited by: ramya sri ]
Pratap koritala
Ranch Hand

Joined: Sep 27, 2006
Posts: 252
not worth to be asked for real scjp,options are not clear
pengfei cao
Greenhorn

Joined: Dec 18, 2006
Posts: 4
Try this
code:

abstract class TestClass
{
transient static int j;
synchronized static int k;
final void TestClass(){}
static void f()
{
k = j++;
}
}


The result is

modifier synchronized not allowed here
synchronized static int k;
^
1 error

That is all!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Abstract class??
 
Similar Threads
modifiers question from dan's exam
Abstract Class?
inhertence of abstract ()
transient ????
Why the result of printing out the not-letter chars to console is different from to applets