Athira Vineeth

Greenhorn
+ Follow
since Sep 06, 2010
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
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Athira Vineeth

Make a class immutable by following these guidelines :

ensure the class cannot be overridden - make the class final, or use static factories and keep constructors private
make fields private and final
force callers to construct an object completely in a single step, instead of using a no-argument constructor combined with subsequent calls to setXXX methods (that is, avoid the Java Beans convention)
do not provide any methods which can change the state of the object in any way - not just setXXX methods, but any method which can change state
if the class has any mutable object fields, then they must be defensively copied when passed between the class and its caller
For more details refer this link

http://www.javapractices.com/topic/TopicAction.do?Id=29


Thanks,
Athira
5 years ago
Hi

I have two class A and B, where B extends A.



Main class



In this case it will print" Inside B:Print Me"
That means Object a of reference ClassA has access to the method defined inside ClassB.

But if i call a.printMy();then it is showing compilation error.
Why so?

Thanks in Advance
Athira
5 years ago
hi

try this
[Moderator action: Removed ready-made solution. Athira Vineeth, please DontBeACodeMill.(⇐click)]
5 years ago
Hi

Hope this will work
5 years ago

yes its help me a lot.

thank you so much for your time.
5 years ago
Hi

in the below example


The output of this program is "String".
Why so?Why it is not executing the printValue(Object ob) method?
5 years ago
To compare two objects for equality you can override equals method.

Thanks
Athira
5 years ago
Hi

In java it is not possible to instantiate an abstract class. Then why there need a constructor inside abstract class?

Thanks in Advance
Athira
5 years ago
Thanks Brown!!

that link is very helpful.

it is clear now
From this example

output is Goodnight, Dick

Thanks
Athira
5 years ago
In a class hierachy, when a method in a subclass has the same name and type signature as a method in its super class, then a method in the subclass is said to override the method in the super class.
When an overriden method is called from within a subclass, it will always refer to the version of that method defined by the subclass.The version of the method defined by the superclass will be hidden.

In that sense main method is said to be overriding.right?
5 years ago
hi

i think it is because


locationCells is not empty so it is always printing hit. in the first code

after changing the if(index>=0) position ,the execution never entered into if(index>=0){ block

so the default value got printed "miss"
5 years ago
Thanks for the reply.

But still i am in confusion

i have a class called MainClass


one subclass called that xtend main class



here the signature of main method is same that means main method got overriden .right?
5 years ago
Hi

Is it possible to override main method?

Thanks in Advance
Athira
5 years ago
Hi,

intern() method
Returns a canonical representation for the string object.
A pool of strings, initially empty, is maintained privately by the class String.

When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned.

It follows that for any two strings s and t, s.intern() == t.intern() is true if and only if s.equals(t) is true.

For example

try this


this will output false

try this


this will output true
5 years ago