K S HEGDE

Greenhorn
+ Follow
since Apr 21, 2007
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by K S HEGDE

Dear friends,

Why do two methods of Object class, clone() and finalize(), are protected
while other methods are public?

Thank You
K S Hegde
Dear Friends,

"==" checks the equality of object references
equals() checks the equality of contents of the objects

Hence only option "C" is right

thank you

K S Hegde
Dear Srikant Ramu,

Thanks for the correct code.

Yours
K S Hegde

Dear Campbell Ritchie,

Thanks for the explanation.

yours
K S Hegde
18 years ago
Dear Burkhard Hassel
Here is my code:

package user;
import user.java2.*;
public class AccessModifier
{
private String licensePlate="MH-05-G-2345";
public String make="Hero Honda";
String model="Vector";
protected int year= 2007;

public static void main(String arg[])
{
AccessModifier am = new AccessModifier();
AccessModifierProtected am1 = new AccessModifierProtected();

System.out.println();
System.out.println("This Printout is from AccessModifier class");
System.out.println("The Motorcycle whose license plate number is : " +am.licensePlate);
System.out.println("The Motorcycle is : " + am.make);
System.out.println("And the Model is : " + am.model);
System.out.println("It is manufactured in : " + am.year);

am1.ampd();


}
}

package user.java2;
import user.*;
public class AccessModifierProtected extends AccessModifier
{
public void ampd()
{
AccessModifier am = new AccessModifier();
// System.out.println("The Motorcycle whose license plate number is : " +am.licensePlate);
System.out.println();
System.out.println("This Printout is from AccessModifierProtected class");
System.out.println("The Motorcycle is : " + am.make);
// System.out.println("And the Model is : " + am.model );
//System.out.println("It is manufactured in : " + am.year);
}

}
18 years ago
I have made package and used all access modifiers for fields.
In super class I have put,
private String lp = "MH-01-1234";
public String make = "Hero";
String model = "Honda";
protected int year = 2007;
The super class is put in "user" package and subclass is put in
"user.java2" package.
I tried to access "year" in sub class but could not. The compilation error it shows is "the field 'year' is protected in parent class" If disable this usage other things work fine.

Kindly guide.

Thanking you
yours
K S Hegde.
18 years ago