Golam Newaz

Ranch Hand
+ Follow
since Jan 08, 2001
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 Golam Newaz

Hi,
I think your program is like this:
class sup{
}
class sub extends sup{
void meth(){}
}
public class supsub{
public static void main( String argv[] ){
sup s=new sub();
s.meth();
}
}

I do agree with rogers. And also if we say in other way,
you are making instance of sub class but type is sup i.e.
super class and your meth() method didn't find any equavalent method which it would override in super class. So meth() method is being created as a new method in your subclass not overridden
method in super class. So how come type super class works.
- Golam Newaz

- Golam Newaz

------------------
Hi,
I found in java API that EventListener is a tagging interface.
Why we can not say this super interface?
Need an explanation.
- Golam Newaz
------------------
Sorry i did a mistake in example. The first line
should be the followings:
class Prioritytest extends Thread{
Thanks,
- Golam Newaz
------------------
Hi,
Kindly compile and run this program. I am confused about
thread priority. If i uncomment the try block then i get
message without priority system but with comments i
get message in priority system but does not follow acutal system like MAX, NORM, MIN. And also priority should be started before executing try block. But it doesn't work.
My Question:
1. does this example show that priority always depends on
platform?
2. When priority should be started in this example. Is before
try block or sleep() method stops priority system?
Example:
Prioritytest( String s){
super(s);
}
public void run(){
for( int i=0; i<5; i++){
System.out.println(getName()+":"+ i);
}
}
}

public class testbyte{
public static void main( String argv[]) throws InterruptedException{
Prioritytest ab1=new Prioritytest("Say");
Prioritytest ab2=new Prioritytest("Sam");
Prioritytest ab3=new Prioritytest("Mee");
ab1.setPriority(Thread.MIN_PRIORITY);
ab2.setPriority(Thread.NORM_PRIORITY);
ab3.setPriority(Thread.MAX_PRIORITY);
ab1.start();
/* try{
Thread.sleep(3000);
}
finally{ } */
ab2.start();
/* try{
Thread.sleep(3000);
}
finally{ } */
ab3.start();
}
}
Need solution.
- Golam Newaz
------------------
Hi,

Normally, sleep(), yield(), stop() and wait() methods will
stop Threads from executing. And 2 is correct because wait(),
notify() and notifyAll() are inter-related and when notifyAll wakes up all the threads that call wait on same object. the highest priority thread that wakes up will run first. So
calling highest priority thread you stop Threads,
- Golam Newaz
Hi Lokesh,
You put another one keyword into your program ie. final.
So we have to think two things. One static and one is final.
Look i changed your program a little in line no.2 just
dropped out static i got the following output.
Output:
The static method java.lang.String show() declared in class
Sub cannot hide the instance method of the same signature
declared in class Super. It is illegal to hide an instance
method.
The method void show() declared in class Y cannot override the final method of the same signature declared in class X. Final methods cannot be overridden.

1 class X {
2 public final void show() {
3 System.out.println("Hello Java");
4 }
5 }
6
7 public class Y extends X {
8 public static void show() {
9 System.out.println("Hello C++");
10 }
11 }
So it has been proved that static method related with hidden not override.
- Golam Newaz
Hi Venkat,
Static method cannot be overridden in any way.
A hidden class (static) method can be invoked by using a reference whose type is the class that actually contains the declaration of the method. In this respect, hiding of static methods is different from overriding of instance methods.
Class method cannot be overridden. The example:
class Super {
static String greeting() { return "Goodnight"; }
String name() { return "Venkat"; }
}
class Sub extends Super {
static String greeting() { return "Hello"; }
String name() { return "shashank"; }
}
class Test {
public static void main(String[] args) {

Super s = new Sub();
System.out.println(s.greeting() + ", " + s.name());

}
}
produces the output:
Goodnight, Shashank.
because the invocation of greeting uses the type of s, namely Super, to figure out, at compile time, which class method to invoke, whereas the invocation of name uses the class of s, namely Sub, to figure out, at run time, which instance method to invoke.
Actually we have to think about class method ie static method
and instance method ie. non-static method. Class method can
not be overriden except hiding in other hand instance method
should be overridden.
- Golam Newaz
------------------
Hi Dave,
I came across your advertisment. I hope that my experience are
wellset for the post. I am really interested to work with you.
I have a legal employment authorisation in USA. Presently, i am staying at Huntington Beach , California.
Kindly find my resume in webpage format along with my recent projects.
http://www.webbangladesh.com/Sayeed/Myresume.html
My e-mail: newaz@cheerful.com
Tel : 714-894-9038
Best regards,
Golam Sayeed Newaz

------------------
17 years ago
Hi,
Val and siva, both of you are correct. But my question came in different way. I want to know why abstract modifier is dropped out of interface and of methods. After reviewing your reply, i
checked java.sun.com and found the following which actually
i was looking for.
1. abstract interfaces:
- Every interface is implicitly abstract. This abstract modifier is obsolete and should not be used in new programs.
2. abstract methods of the body of abstract interface:
For compatibility with older versions of the Java platform, it is permitted but discouraged, as a matter of style, to redundantly specify the abstract modifier for methods declared in interfaces.
It is permitted, but strongly discouraged as a matter of style, to redundantly specify the public modifier for interface methods.
Am i right.
- Golam Newaz
------------------
Hi,
I am little bit confused about interface and abstract.
I found this question in onesite.
8) What is the difference between interface and an abstract class?
Ans : All the methods declared inside an Interface are abstract. Where as abstract class must have at least one abstract method and others may be concrete or abstract.
*I checked WindowListener interface in java API, but i didn't
get any abstract method. I think abstract keyword should be
written before the method.
Can anyone clarify that,

Hi Malathi,
Before going into your question, we have to explore about constructor.
Sometimes a class contains many constructors and each constructor allows the caller to provide initial values for different instance variables of the new object. For example, java.awt.Rectangle has these three constructors:
Rectangle() {
this(0,0,0,0);
}
Rectangle(int width, int height) {
this(0,0,width,height);
}
Rectangle(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
The no-argument constructor doesn't let the caller provide
initial values for anything, and the other two constructors let the caller set initial values either for the size or for the origin and size. Yet, all of the instance variables, the origin and the size, for Rectangle must be initialized. In this case, classes often have one constructor that does all of the work.
The important is that The other constructors call 'this' constructor and provide it either with the values from their parameters or with default values. For example, here are the possible implementations of the three Rectangle constructors shown previously (assume x, y, width, and height are the names of the instance variables to be initialized):
Now we can come to question in how 'do everything same as a single argument. So if you call a Constructor like
Example a=new Example( 10, 12);
Look which Constructor we are calling definitely second one
as per Sivalingan's modified program. Here you are calling second
constructor and inside that Constructor you are calling
this(a); that means you are calling 1st constructor( following one ) which we can compare with this(a). So at the same you are
doing everything using one Constructor arguments.
public Example( int a){
x=a;
}
Understood it,
- Golam Newaz
Hi Melly,
I came across your advertisment. I hope that my experience are
wellset for the post.I have a legal employement authorisation in USA. Presently, i am staying at Huntington Beach , California.
Kindly find my resume in webpage format along with my projects
recently done by me.
http://www.webbangladesh.com/Sayeed/Myresume.html
MY e-mail:newaz@cheerful.com
Tel : 714-894-9038
Best regards,
Golam Sayeed Newaz

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

------------------
17 years ago
We can solve this problem using a question.
Q. When base class calls a method, how could the run time knows to called the overridden method in the derived class? The object is not even constructed yet.
A:
Why? From the language theory, it is called deferred binding or dynamic binding or binding at run time. Compiler leaves the decision to run time. To make the decision at run time, you don't need the object built first. The only thing you need to know is the type of the actual object.
In Java, the Class (not class) object is load to the memory when it is first used. The run time knows it before any instance is constructed.
Look in your example:
Answer definitely should be 2) not 3) i.e b not c. Because if we think about run time binding and compile time binding then it should be clear. In your example very very important is that look the comments // in answer:
2)
RType.amethod // Before making any object.
99 // After making object.
RType.amethod // After making object.
So when you leave this decision at run time, it first find what type of object it is before making any instance of object. In your example,
Base b=new RType();
your Type is Base and your Base class has a Constructor and that constructor calls amethod(), which is overridden and after that
instance of object works.
Could i make you understand,
- Golam Newaz

------------------
Kindly put the following line into your Applet changing link.
But it should be with a new window. I could give you the code
which should be pasted into your current window but it is
1:30 am at night. I am so tired. Good bye
try {
this.getAppletContext().showDocument(new URL("http://www.webbangladesh.com"),"newWindow");
}
catch (MalformedURLException e){}

- Golam Newaz
------------------
17 years ago
Hi,
I complied Gaurav's program and it is ok that static method is not overridden but what about static variable. Look the following example and run it and static variable is overridden.
I don't understand why this is the difference because both of them are class variable and class method.
class Testthis{
boolean avariable;
static public int i=5;
Testthis(){}; // Constructor 1.

Testthis(boolean avariable, int i){ // Constructor 2.
this.avariable=avariable;
this.i=i; // assigning to the member class/static variable i.

}
}

public class Testoverride extends Testthis{
public static void main( String argv[] ){
Testthis th=new Testthis( true,10 ); // used constructor
// no.2 of superclass.
System.out.println(th.avariable); // avariable is an
// instance variable
// of class Testthis
// super class
System.out.println(th.i);
System.out.println(Testthis.i);

}
}
Output is:
true
10
10
- Golam Newaz

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