Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!

Agandhi

Greenhorn
+ Follow
since Oct 17, 2003
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Agandhi

Thanx Animesh .... .subclass-outside-the-package I didn't read this properly.

Thanks for clearing my doubt.
Amit,

In java override is applicable to methods not to member variables.

thanks,
Gandhi.
Hi Animesh,

I am little confused with the explaination you have given with the example SubRanchQ.

code:

package javaQ;
public class Parent
{
protected void calculate() { }
}

package java;
import javaQ.Parent;
class SubRanchQs extends Parent
{
void callCalculate()
{
SubRanchQs rq = new SubRanchQs();
rq.calculate();
}
}

class SubSubRanchQs extends Parent
{
void callCalculate()
{
SubRanchQs rq = new SubRanchQs();
rq.calculate(); // U get a compiler error here
}
}

---------------------------------------------------------------------------

U said the classes SubRanchQs and SubSubRanchQs are in a different package. If the classes are in different package then it should give a compiler error when you try to instantiate SubRanchQs in SubSubRanchQs

SubRanchQs rq = new SubRanchQs(); //compiler error

Also in the second example

class SubRanchs extends Parent
{
void callCalculate()
{
Parent rq = new Parent();
rq.calculate();
}
}

You have created an instance of Super class in a subclass and are using the dot operator on the super class which will give compile error.

The K & B book says that

So if the subclass-outside-the-package gets a reference to
the superclass (by, for example, creating an instance of the superclass somewhere in the subclass� code), the subclass cannot use the dot operator on the superclass reference to access the protected member.

So can you please clarify me if I am wrong

Thanks,
Gandhi.
hi all,

if a class dosen;t have any access specifier, what is the default access specifier for it.....??
and as said in the thread above, what is a package access scope???

If a class doesn't have any access modifier attached to it then it will have DEFAULT access modifier. The package scope is nothing but you will have access to the constuctors and methods of other classes if accessing class is in a same package.

i've one more doubt....
they say that a class can only be extended if the extending class is in the same package or if we import the class to be extended..am i right???

You are right if the extending class has a default access modifier to it. But say the extending class has a public access modifier then you can extend that class even if it's in a different package.

then if we write two classes in same file(one class extending the other) and define one variable with default access in the base class, can this be accessed by the derived class???

Yes you can access the variables defined in the parent class. Once a child class extends the parent class, chld class can do everything which a parent class can do, but it's not true the other way round.

i more doubt...
is it true that default cnstrtr takes the acess specification from its enclosing class in every case???

A default constructor always has a default access in a class and it doesn't inherit anything by extending a class. You can changes the access modifier of a constructor then it;s not a deault constructor anymore.

Thanks ..
Hi There,
I am trying to print PDF files using javax.print API. It prints the PDF files, but it's printing all junk characters. Can anyone direct me how to go about this?I tried
flavor = DocFlavor.INPUT_STREAM.PDF;
also
flavor = DocFlavor.BYTE_ARRAY.PDF;
Thanks,
Gandhi.
16 years ago
Hi Marlene,
I understood your explaination, except for final String s3 = new String("abc"). Why can't we call it as compile-time constant?
Thanks..