[Show all top banners]

Robert Frost
Replies to this thread:

More by Robert Frost
What people are reading
Subscribers
:: Subscribe
Back to: Kurakani General Refresh page to view new replies
 Java problem-help needed
[VIEWED 3199 TIMES]
SAVE! for ease of future access.
Posted on 09-27-04 12:01 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Alright here's my problem:

package questions.c1;
interface RiceCereal {
public void snap();
public void crackle();
public void pop();
}
public abstract class Krispies implements RiceCereal {
public void snap() {
System.out.println( "Snap!" );
}
public void crackle() {
System.out.println( "Crackle!" );
}
public static void main( String[] args) {
Krispies k = new Krispies();
k.snap();
}
}

The problem I get from compiling this code is that:
"Krispies is abstract and it cannot be instantiated" showing me the code "new Krispies" as the culprit. I am relatively new to Java and I was debugging a problem, now I am stuck with this, it debugged my whole brain. Searched through the net, and could not understand the solution from sun.java.com. My sajha friends, I need help.
 
Posted on 09-27-04 10:55 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

I am still waiting....Anyone??
 
Posted on 09-27-04 11:04 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

How about changing:
public abstract class Krispies implements RiceCereal

to

public class Krispies implements RiceCereal
 
Posted on 09-27-04 11:17 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Abstract classes aren't supposed to be instatiated, hence your problem.
Couple of options: like mallazi said, don't declare your class to be abstract.
Or, make another class and extend the abstract class.

 
Posted on 09-28-04 12:37 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

I ommitted the abstract, the error was that Krispies should be declared abstract. I declared abstract and it says cannot be instantiated. So I am guessing I will have to override or follow up with a sub-class to extend it. Question is how can it be done? Any idea as to how to make an extension?
 
Posted on 09-28-04 6:12 AM     Reply [Subscribe]
Login in to Rate this Post:     0       ?    
 

Remove the main method from Krispies.
Create another class extending Krispies as:
public class XXX extends Krispies{
}
and plug the main method here and do whatever you need.

 


Please Log in! to be able to reply! If you don't have a login, please register here.

YOU CAN ALSO



IN ORDER TO POST!




Within last 365 days
Recommended Popular Threads Controvertial Threads
श्राद्द
TPS Re-registration
सेक्सी कविता - पार्ट २
What are your first memories of when Nepal Television Began?
पाप न साप घोप्टो पारि थाप !!
पुलिसनी संग - आज शनिवार - अन्तिम भाग
निगुरो थाहा छ ??
ChatSansar.com Naya Nepal Chat
TPS Re-registration case still pending ..
Lets play Antakshari...........
What Happened to Dual Citizenship Bill
Basnet or Basnyat ??
Sajha has turned into MAGATs nest
NRN card pros and cons?
मेरो अम्रिका यात्रा -२
Do nepalese really need TPS?
कता जादै छ नेपाली समाज ??
susta manasthiti lai ke bhanchan english ma?
कृष्ण नै अन्तिम सत्य
पुलिसनी संग - आज शुक्रवार - भाग २
Nas and The Bokas: Coming to a Night Club near you
राजदरबार हत्या काण्ड बारे....
Mr. Dipak Gyawali-ji Talk is Cheap. US sends $ 200 million to Nepal every year.
Harvard Nepali Students Association Blame Israel for hamas terrorist attacks
TPS Update : Jajarkot earthquake
is Rato Bangala school cheating?
NOTE: The opinions here represent the opinions of the individual posters, and not of Sajha.com. It is not possible for sajha.com to monitor all the postings, since sajha.com merely seeks to provide a cyber location for discussing ideas and concerns related to Nepal and the Nepalis. Please send an email to admin@sajha.com using a valid email address if you want any posting to be considered for deletion. Your request will be handled on a one to one basis. Sajha.com is a service please don't abuse it. - Thanks.

Sajha.com Privacy Policy

Like us in Facebook!

↑ Back to Top
free counters