1,105,290 Community Members

problem with inerface in java

Member Avatar
mallikaalokam
Light Poster
36 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 
import java.lang.*;
import java.io.*;
import java.util.*;
  
interface Batm
{
   final static int minbal=500;

    abstract void withdrawl();

}

 class Bal implements Batm
{
    int amt,cbal;
  Bal(int amt,int cbal)
   {
     this.amt=amt;
     this.cbal=cbal;
    }
 
    void withdrawl()
     {
        if(cbal>minbal)
            {
                   cbal=cbal-amt;
                 System.out.println(amt+" "+"withdrawn");
             }
          else
            {
              System.out.println("bal nt sufficient");
             }
      }
}

 class Atm
 {
    public static void main(String args[])throws IOException
      {
        

             Bal b=new Bal(2000,5000);
         b.withdrawl();

         }
}

m getting an error dat
attempting to assign weaker access privilges.can not implement withdrawl in bal in batm

Member Avatar
DavidKroukamp
Master Poster
737 posts since Dec 2011
Reputation Points: 105 [?]
Q&As Helped to Solve: 180 [?]
Skill Endorsements: 4 [?]
Team Colleague
Featured
 
0
 

import java.lang.*;
import java.io.*;
import java.util.*;

interface Batm
{
final static int minbal=500;

abstract void withdrawl();

}

class Bal implements Batm
{
int amt,cbal;
Bal(int amt,int cbal)
{
this.amt=amt;
this.cbal=cbal;
}

void withdrawl()
{
if(cbal>minbal)
{
cbal=cbal-amt;
System.out.println(amt+" "+"withdrawn");
}
else
{
System.out.println("bal nt sufficient");
}
}
}

class Atm
{
public static void main(String args[])throws IOException
{


Bal b=new Bal(2000,5000);
b.withdrawl();

}
}


m getting an error dat
attempting to assign weaker access privilges.can not implement withdrawl in bal in batm

why have you got two withdrawl methods, one abstract(and no code) the other public(and has code)? also see here:http://docs.oracle.com/javase/tutorial/java/IandI/abstract.html and here:http://docs.oracle.com/javase/tutorial/java/IandI/usinginterface.html and this:http://java.sun.com/docs/books/jls/second_edition/html/interfaces.doc.html, http://docs.oracle.com/javase/tutorial/java/concepts/interface.html and this just for extra :):http://www.java-examples.com/java-interface-example

[EDIT] or just:

interface Batm
{

abstract void withdrawl();

}

class Bal implements Batm
{
Bal(int amt,int cbal)
{
}

    @Override
public void withdrawl()
{
}
}

public class ATM
{
public static void main(String args[])throws IOException
{
}
}


}
Member Avatar
mallikaalokam
Light Poster
36 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

why have you got two withdrawl methods, one abstract(and no code) the other public(and has code)?

i want t knw how to implenet iterfaces
as interfaces cn nly have final static varibles nd abstarct methods
i took dat way
m a learner pls help me

Member Avatar
DavidKroukamp
Master Poster
737 posts since Dec 2011
Reputation Points: 105 [?]
Q&As Helped to Solve: 180 [?]
Skill Endorsements: 4 [?]
Team Colleague
Featured
 
0
 

i want t knw how to implenet iterfaces
as interfaces cn nly have final static varibles nd abstarct methods
i took dat way
m a learner pls help me

Please see my edited post added three links

Member Avatar
JamesCherrill
... trying to help
10,362 posts since Apr 2008
Reputation Points: 2,081 [?]
Q&As Helped to Solve: 1,749 [?]
Skill Endorsements: 47 [?]
Moderator
Featured
 
0
 

Methods declared in an interface are automatically public and abstract, so the method definition in the class that implements must be declared public, as default access is more restricted

Member Avatar
mallikaalokam
Light Poster
36 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Methods declared in an interface are automatically public and abstract, so the method definition in the class that implements must be declared public, as default access is more restricted

yes got it
tq tq tq

Question Answered as of 2 Years Ago by DavidKroukamp and JamesCherrill
Member Avatar
JamesCherrill
... trying to help
10,362 posts since Apr 2008
Reputation Points: 2,081 [?]
Q&As Helped to Solve: 1,749 [?]
Skill Endorsements: 47 [?]
Moderator
Featured
 
0
 

Never thought about this before, bit it is a bit weird - you declare a method with default scope in an interface, implement that in a class also with default scope, and its an error. :-O

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: