tim bond

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

Recent posts by tim bond

k.mughal exam is necessary as a benchmark.
it contains more tougher questions however the trickyness
remains the same.
also prepare using k.mughal book because some of the advanced
concepts have been clearly explained with excercises and
examples.
all the best .
remember the sure path to score above 90 in scjp
is k&B book along with k.mughal book .
prove to the world you are one of them.
my humble request is to do scjp 1.4 and then
do scwcd or scbcd ( which is very important)
after which the interviewers generally ask one or two basic
questions and simply give appt letter.
if you are in india don't waste time in scjp 1.5 it is waste.
for job scjp 1.4
then scbcd or scwcd ( very important)
assured job within 2 or 3 months in mncs like
ibm; wipro; accenture etc.
don't waste time hurry up.
vacancies will be over by aug 2006.
if you have studied for scjp 1.4 please take that exam itself.
scjp 1.5 or scjp 1.4 no body really cares.
at the time of interview it is more of your answers to the interviewer
which will matter.
/*What is the result of attempting to compile and run the program?

a. Prints: 1,3
b. Prints: 2,3
c. Prints: 1,4
d. Prints: 2,4
e. Run-time error
f. Compile-time error
g. None of the above


The answer given is a, my answer is b, since x is static variable it should be incremented in the method m1 and we should get the result 2,3

can we hide the static variable with local variable like above? */


hi the answer is a. 1,3 because there are 2 xs one is static x and other is local x of m .

when we call m(x,y)
and we are printing the values of static x and the variable y of the class.
since it is pass by value; the x and y in the m(x,y) get incremented to 2 and 4.
However the static x and the class variable y remain 1 and 3.
AmbiguosMethodCall.java : somethin(int) is already defined.

compiler error is obtained .



given options c is not correct bcoz it says method with different return types are not allowed.
which is wrong if the methods are overloaded.
now we should not think that these options refer to this question only.


option b is correct because as the error states the something(int) is already defined. so it is ambiguos to call this method.
eb Mathe
ranch hand
Member # 107996
posted December 13, 2005 07:01 AM
--------------------------------------------------------------------------------
you need to pass the scjp again or improve yourself to know that the static method can be called by both the class name and instance name .



I think Jeff's example is not a good one :



Static method can be inherited
example below


public class Test1
{
public static void testMethod()
{
System.out.println("Testing");
}
}

public class Test2 extends Test1
{
public static void main(String[] args)
{
Test2 test2 = new Test2();
test2.testMethod();
}
}

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



because test2.testMethod() doesn't make sense.
It should be : Test2.testMethod()



so both Test2.testmethod(); class calling static method;
and test2.testmethod(); instance calling static method;


boss
do it and see.
class Sup{

public Sup(String str){

System.out.println("Super class");

}

}


public class Test2 extends Sup{

public Test2(String str){

System.out.println("Sub class");

}

public static void main(String[] args) {

Test2 t2 = new Test2("22");

}

}



the solution is to insert


super(str);



in class Test2

public class Test2 extends Sup{

public Test2(String str){

super(str); // insert the super call with the argument.

System.out.println("Sub class");

}

public static void main(String[] args) {

Test2 t2 = new Test2("22");

}

}


This will resolve the issue.
class Y is a subclass of class X. will this compile?

Class X objX = new Class X();
Class Y y= (Class Y) objX;

Ans: YES.

can anybody explain me why?


Class X objX = new Class X();
objx is an object of class x



class x is the superclass of class y



Class Y y= (Class Y) objX;

here you are creating a reference y (not an object)
and objx is being assigned to this reference y.
and the objx is being downcasted using (Class y).

thats why it is getting compiled.
please read about casting
what you are doing is down casting
the class x object to class y
or you have to modify the public void op()throws MyException{
System.out.println("2");throw new MyException();}}
to
public void op(){
System.out.println("2");throw new MyException();}}
this will then print 2 and 1 ;
public class Math{ public class MyException extends Exception{}
public static void main(String[] args){
MathObj m=new MathObj();
try{ m.op();}
catch(MyException e){ System.out.println("1");} }
public void op()throws MyException{
System.out.println("2");throw new MyException();}}
class MathObj extends Math{
public void op(){ System.out.println("3");}}

in the first m is object of Mathobj and reference of MathObj. to resolve the error
you need to remove the System.out.println("2");throw new MyException();
to System.out.println("2"); as the exception is already in try and catch block.
there is no need to throw it again. This is causing the error.

public class Math{
public class MyException extends Exception{}
public static void main(String[] args){
Math m=new MathObj(); try{ m.op();}
catch(MyException e){ System.out.println("1");} }
public void op()throws MyException{
System.out.println("2");throw new MyException();}}
class MathObj extends Math{
public void op(){ System.out.println("3");}}


here the m is object of Math but reference of MathObj. so it just executes the m.op in class mathobj .
thanks but what about the public access case
in the client.java
and charstack.java
i've been studying khalid for 1 month.
I thought practicals will be easy after theory.
but when i executed the first program.


1)i got "exception in thread "main" java.lang.NoClassDefFoundError:"
then set it right
by using
set CLASSPATH=c:j2sdk1.4.2_07\bin;%CLASSPATH%;

please help me in setting the classpath and path in environment variables
2) when i tried executing example 1.4 which is Client.java
This Client.java accesses CharStack.java which is having public access and is present in the same folder as Client.java however i get error
Client.java can't resolve symbol
Class CharStack .
i get the error
then i created CharStack.class but still same error.
then i copied CharStack class into Client.java
then i got error CharStack is public and must be declared in a CharStack.java file.

then i have to make
public class CharStack as
class CharStack and execute
or i have to make
public class Client as
class Client and execute.

but what i want to know is how to use the public access in both of them
do i need to set the classpath .
please help me in setting classpath
please uninstall both the jdk 1.5 and the previous versions of jdk that you have installed. restart the system and then install only the jdk 1.5.
also check the path and classpath in environment variables of the device manager.
18 years ago
please provide weblinks for free mock exams for scjp 1.4