This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes can somone help me out with this program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "can somone help me out with this program " Watch "can somone help me out with this program " New topic
Author

can somone help me out with this program

sarvesh dikonda
Ranch Hand

Joined: Apr 08, 2012
Posts: 58

given: an interface A; an abstract class Abstract_A and a class Testmain. I need to make use of both the interface and abstract class in the Testmain class. its very simple i know but when i compile it its showing syntactical errors which is actually violating the question's conditions.

package com.scjppracticequestions ;

public abstract interface A
{
public int a=0;
public static final int CONST=0;
public abstract int setA();
}

package com.scjppracticequestions ;

public abstract class Abstract_A
{
public String s;
public abstract void setS();
public String getS()
{
return s;
}
}


[code=java]package com.scjppracticequestions ;

import com.scjppracticequestions.*;

public class Testmain extends Abstract_A implements A
{
public static void main(String args[])
{
Testmain tm=new Testmain();
tm.go();
}

public void go()
{

// public void
setS()
{
s="***Ganpati Bappa Morya***";

}
// public
String getS()
{
return s;
}
CONST=4;
System.out.println("CONST="+CONST);
// public
int setA()
{
a=1;
return a;
}
System.out.println("a="+setA());
}
}



Always believe in yourself
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11354
    
  16

If you are getting compiler errors, please post them in their entirety (or at least, the first few). Those errors MEAN something, and often tell you EXACTLY what is wrong.

If they violate the questions conditions, tell us what those conditions are and HOW they violate the conditions.

Without that information, there isn't much anyone can do to help.

It would also help GREATLY if you used code tags - this preserves your formatting. Click the 'code' button above where you enter your post, and then past your java between the ']' and the '['. Then it looks like this when displayed:



There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
sarvesh dikonda
Ranch Hand

Joined: Apr 08, 2012
Posts: 58

fred rosenberger wrote:If you are getting compiler errors, please post them in their entirety (or at least, the first few). Those errors MEAN something, and often tell you EXACTLY what is wrong.

If they violate the questions conditions, tell us what those conditions are and HOW they violate the conditions.

Without that information, there isn't much anyone can do to help.

It would also help GREATLY if you used code tags - this preserves your formatting. Click the 'code' button above where you enter your post, and then past your java between the ']' and the '['. Then it looks like this when displayed:




The actual question is as follows which has the conditions in it:
Create an interface that has methods and a constant.Create an abstract class with an abstract method, a non-abstract method, and an instance variable.Create a concrete class that uses both of the above.

Below i have given the code of only the Testmain class because the interface and the abstract class A are compiling properly.


When i compile the Testmain class i get the errors as follows:

E:\JAVA programs\Study Projects\Sec-1 Declarations,Initialization,Scoping\1.a\Te
stmain\src>javac -d ..\classes com\scjppracticequestions\Testmain.java
com\scjppracticequestions\Testmain.java:17: ';' expected
setS()
^
com\scjppracticequestions\Testmain.java:23: ';' expected
String getS()
^
com\scjppracticequestions\Testmain.java:30: ';' expected
int setA()
^
3 errors

Please let me know if there is a mistake only in the Testmain class or do i also need to do changes in the interface and the abstract classes repectively.
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1180
The following is a variant of your code that does compile. Maybe it's a better starting point....



William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
sarvesh dikonda
Ranch Hand

Joined: Apr 08, 2012
Posts: 58

Dan Drillich wrote:The following is a variant of your code that does compile. Maybe it's a better starting point....


Thank you for your help Dan. Actually i too had tried too do that before but somewhere there was a problem. Also thank you Fred for your guidance & helping to present my problem in a proper manner.

Now i am trying to get a the value of the String 's' ,which i had set to a value in my Testmain class.But when i try to print the value of 's' in the main class it is showing null value. This 's' is the instance variable of abstract class Abstract_A
sarvesh dikonda
Ranch Hand

Joined: Apr 08, 2012
Posts: 58

sarvesh dikonda wrote:
Thank you for your help Dan. Actually i too had tried too do that before but somewhere there was a problem. Also thank you Fred for your guidance & helping to present my problem in a proper manner.

Now i am trying to get a the value of the String 's' ,which i had set to a value in my Testmain class.But when i try to print the value of 's' in the main class it is showing null value. This 's' is the instance variable of abstract class Abstract_A


Thank you Dan and Fred. I'm through with my problem. I experimented a lot with the code and finally i got it. Actually, i am preparing for OCJP 6 exam and i have finished reading Head First JAVA and i have also given few practice tests from a Java Simulator software. I have to give this OCJP 6 this time but i just want to ensure that i am fully prepared before i give my actual exam. If you guys could suggest me some tips and tell if i am going in the right way. Should i code or first or should i start giving practice tests as i am doing and if i get stuck with some concept look for the SOLUTION there and there.
 
GeeCON Prague 2014
 
subject: can somone help me out with this program