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 few questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "few questions" Watch "few questions" New topic
Author

few questions

preety kumari
Greenhorn

Joined: Nov 03, 2000
Posts: 3
can anyone help me with these questions?
(some sounds easy, but I am confused)
Are these true or false?
1. Transient variables maust not be static or final.

2.static methods are implicitly final, because overriding is done based on the type of the object, and static methods are attached to a class, not an object.(answer is true)
3. abstract methods cannot use the following modifiers;private,static, final, native or synchronized.(answer given is true)
Amit Tyagi
Ranch Hand

Joined: Oct 18, 2000
Posts: 52
hI preety ,
Transient variable can be final static private ....
You better try to write one line of code and then see your self...
bye
Amit
class tras
{
private static final transient int i = 0;
}
The above code will compile properly.
Supriya
Greenhorn

Joined: Oct 27, 2000
Posts: 9
can anyone explain this:
private methods can be overrided if superclass is non-abstract.
private methods cannot be overriden if superclass is abstract.
why is it so?
Aru Ven
Ranch Hand

Joined: Sep 28, 2000
Posts: 199
Supriya,
1. private methods can be overrided if superclass is non-abstract.
- The private methods belong only to the class & are not visible outside the class. When u subclass a class with private methods,
u can again declare the private methods in the subclass.
This Is NOT OVERRIDING. Because the Parent class private methods are not visible nor accessable to the Child class.
Look at a simple example here -
class abs{
private int i = 1;
private void ab(){};
}
class abst extends abs{
private int i = 100;
private void ab(){ // not overriding
System.out.println(i); // prints 100
}
public static void main(String a[]){
new abst().ab() ;
}

}

2. private methods cannot be overriden if superclass is abstract.
- Abstract methods can't be private. Since the class which extends the abstract class provides the defination for the abstract methods. If the method is abstract method is private there is no way it is accessible outside the class.
HTH,
Aruna
Supriya
Greenhorn

Joined: Oct 27, 2000
Posts: 9
thanks Aruna.
i got the point.i tested it with the following code:
public class Base{

public static void main(String args[]) {
Base b= new sub();
b.amethod();
}

private void amethod(){
System.out.println("Hey!i am base");
}
}
class sub extends Base{

private void amethod(){
System.out.println("Hey! i am sub");
}
}
It outputs:Hey!i am base
whereas if the amethod is not declared private the out put was:
Hey! i am sub
now i am clear
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: few questions
 
Similar Threads
interface
final and abstract
Clarification of underlying code.
Annonymous classes
Ambiguious Questions...