"use of abstract keyword"

It is permissible that we can use abstract methods with public,protected access specifiers.
But when i tried to do so in inheritance i was getting an error that :
"cannot reduce the visibility of inherited method of Super1(parent class)"
Check the below given example
// program
abstract class Super1
     int a,b;
     abstract void show();//this is working.
     /* The below mentioned are not working*/
     //protected abstract void show();
     //protected abstract void show();
class Sub extends Super1
     void show()
          System.out.println("Abstract method implemented");
class Test
     public static void main(String args[])
          Sub object1=new Sub();
          object1.show();
Plz help me out in knowing why even after access permissions are given it is showing an error.

"cannot reduce the visibility of inherited method of
Super1(parent class)"If a parent class has a public method, that method must be public in all child classes. Here's why: Parent pp = new Child();
pp.someMethod(); Because pp is declared as type Parent, it must honor Parent's contract--it must provide all public methods that Parent does. If Child makes one of those methods protected, package-private, or private, it's violating the contract.
Because a Child can be use wherever a Parent is expected, Child must provide everything that Parent provides.

Similar Messages

  • Use of an abstract keyword

    Hi all , I want to know about
    1.the usage of an abstract keyword.
    2.Difference between abstract and interface
    3.When to use abstract keyword.

    Hi all , I want to know about Give it a try yourself first, post it here and you get feedback.

  • The abstract keyword HELP

    Hi guys, i am having some difficulty in understanding the abstract keyword. When do we use abstract,its purpose and its funtionality?
    Thanks
    roub

    abstract :-
    1:- you can't creat object of abstract class.
    2:- abstract class is supplying the method's signature without giving any definition for it, like void MyMethod(int a);
    3:-abstract class may contain implementation for some methods.
    4:- any class contain an abstract method must defined as abstract.
    5:- when you define abstract method in the heirachery of class you must declare the method as public.
    6:-abstract can have public or default access only.
    7:- you can use reference to abstract class.
    that's all what i can remember now,

  • Use of abstract interface

    I have a series of questions....... Go through.
    What is the use of abstract interface in java ?
    What is the use of static object in java ?
    What is the use of abstract key word to variables ?
    Object reference passed to method are final. Can ' t we change it ?

    class Testing {
         int i;
    public class RefFinal {
       public static void f ( Testing t1, Testing t2) {
           Testing temp;
           temp=t1;
           t1=t2;
           t2=temp;
           System.out.println("value of i in t1 =" +t1.i);
           System.out.println("value of i in t2 =" +t2.i);
       public static void main( String args[]) {
          Testing t1 = new Testing();    
          Testing t2 = new Testing();    
          t1.i=10;
          t2.i=20;
          f(t1,t2); 
          System.out.println("value of i in t1 =" +t1.i);
          System.out.println("value of i in t2 =" +t2.i);
    }      Here the code explain why?

  • How to reference a class without using the new keyword

    I need to access some information from a class using the getter, but I don't want to use the new keyword because it will erase the information in the class. How can I reference the class without using the new keyword.
    ContactInfo c = new ContactInfo(); // problem is here because it erases the info in the class
    c.getFirstName();

    quedogf94 wrote:
    I need to access some information from a class using the getter, but I don't want to use the new keyword because it will erase the information in the class. How can I reference the class without using the new keyword.
    ContactInfo c = new ContactInfo(); // problem is here because it erases the info in the class
    c.getFirstName();No.
    Using new does not erase anything. There's nothing to erase. It's brand new. It creates a new instance, and whatever that constructor puts in there, is there. If you then change the contents of that instance, and you want to see them, you have to have maintained a reference to it somewhere, and access that instance's state through that reference.
    As already stated, you seem to be confused between class and instance, at the very least.
    Run this. Study the output carefully. Make sure you understand why you see what you do. Then, if you're still confused, try to rephrase your question in a way that makes some sense based on what you've observed.
    (And not that accessing a class (static) member through a reference, like foo1.getNumFoos() is syntactically legal, but is bad form, since it looks like you're accessing an instance (non-static) member. I do it here just for demonstration purposes.)
    public class Foo {
      private static int numFoos; // class variable
      private int x; // instance varaible
      public Foo(int x) {
        this.x = x;
        numFoos++;
      // class method
      public static int getNumFoos() {
        return numFoos;
      // instance method 
      public int getX() {
        return x;
      public static void main (String[] args) {
        System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
        System.out.println ();
        Foo foo1 = new Foo(42);
        System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
        System.out.println ("foo1.numFoos is " + foo1.getNumFoos ());
        System.out.println ("foo1.x is " + foo1.getX ());
        System.out.println ();
        Foo foo2 = new Foo(666);
        System.out.println ("Foo.numFoos is " + Foo.getNumFoos ());
        System.out.println ("foo1.numFoos is " + foo1.getNumFoos ());
        System.out.println ("foo1.x is " + foo1.getX ());
        System.out.println ("foo2.numFoos is " + foo2.getNumFoos ());
        System.out.println ("foo2.x is " + foo2.getX ());
        System.out.println ();
    }

  • Use of 'ME' keyword in ABAP Objects?

    Hi all,
       Can any one please  use of 'ME' keyword in ABAP Objects?
    Thanks,
    Vijay.
    Moderator message: next time, please search for available information before asking.
    Edited by: Thomas Zloch on Sep 16, 2010 5:33 PM

    Hi,
    Please find the description about the ME keyword as per the SAP documentation and help.sap.com.
    Within the implementation of every instance method, an implicitly created local reference variable called me is available, which points to the instance in which the method is currently being executed. The static type of me is the class in which the instance method is implemented.
    Each class implicitly contains the reference variable me. In objects, the reference variable mealways contains a reference to the respective object itself and is therefore also referred to as the self-reference. Within a class, you can use the self-reference me to access the individual class components:
    -To access an attribute attr of your class: me->attr
    -To call a method meth of your class: CALL METHOD me->meth
    When you work with attributes of your own class in methods, you do not need to specify a reference variable. The self-reference me is implicitly set by the system. Self-references allow an object to give other objects a reference to it. You can also access attributes in methods from within an object even if they are obscured by local attributes of the method.
    Regards,
    Sagar

  • Why use an Abstract Class ?

    I am new to Java and for some reason I can't get my head around why to use an abstract class. I understand that an abstract class is something like:
    public abstract class Food{ // abstract class
    public void eat(){
    // stub
    public class Apple extends Food{
    public void eat(){
    // Eat an apple code
    }So basically the idea above is that you can eat an "apple" but you can't eat "food" because you can't instantiate an abstract class.
    I understand what an abstract class is and how to write one. What I don't understand is why you would use it? It looks to me like I could have just created a normal class called "Food" and just not instantiated it. What are the benefits of using an abstract class?

    807479 wrote:
    I am new to Java and for some reason I can't get my head around why to use an abstract class.One of the first books I ever read about Object-Oriented design contained the following quote from [url http://en.wikipedia.org/wiki/Lucius_Cary,_2nd_Viscount_Falkland]Lord Falkland:
    "When it is not necessary to make a decision, it is necessary +not+ to make a decision."
    It took me quite a while to understand, but it's all about flexibility: As soon as you cast something in stone, you lose the ability to change it later on if something better/more appropriate comes along. Interfaces and abstract classes are all about delaying that decision.
    As jverd said, interfaces allow you to specify what is required without defining the how; and as ErasP said, abstract classes are usually incomplete: ie, they define some of the 'how', but not all of it.
    What is most important about abstract classes though is that they cannot exist on their own: They must be extended by a concrete class that completes the 'how' before they can be instantiated and, as such, they declare the intent of the designer.
    One of the most important uses of abstract classes is as "skeleton implementations" of interfaces, and there are a lot of examples of these in the Java Collections hierarchy. My favourite is probably AbstractList, which contains a skeleton implementation of a List. Because it exists, I can create a class that wraps an array as a List with very little code, viz:public final class ArrayAsList<T>()
       extends AbstractList<T>
       private final T[] values;
       public ArrayAsList(T... values) {
          this.values = values;
       @Override
       public T get(int index) {
          return values[index];
       @Override
       public T set(int index, T element) {
          T value = get(index);
          values[index] = element;
          return value;
       @Override
       public int size() {
          return values.length;
    };and somewhere else, I can use it:   List<String> letters =
          new ArrayAsList<String>("a", "b", "c");or perhaps, more practically:   List<String> words = new ArrayAsList<String>(
          bigTextString.split(" +") );Now that may not seem like a big deal to you, but given all that Lists can do, it's actually a very powerful bit of code. The above example is from "Effective Java" (p.95).
    HIH
    Winston

  • Use of final keyword on methods arguements ?

    Hi All,
    Just say I have an input arguement for a method which is an int. If I wanted to access the value stored by the input arguement reference inside an anonymous class that is contained in the method one way would be to pass the input arguement reference to a instance variable of the class that contains the method and use that.
    // Declared at start of  class
    int arrayIndex = 0;
    methodName(nt inputNumber)
        arrayIndex = inputNumber;
        ActionListener task = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                // Accessing here
                anArray[arrayIndex] = 100;
    }Just wondering, I used the final keyword on the the input arguement instead and then used the input arguement directly instead. It seemed to work ok. Is this good programming practice or are there some pitfalls to using this that I'm not aware of?
    (I don't need to change what the input arguement reference points to)
    // Alternate
    methodName(final int inputNumber)
        ActionListener task = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                // Accessing here
                anArray[inputNumber)] = 100;
    }Regards.

    declaring it final guarantees that you will not change the value.Of course it does. That's what it's for. That's what it means. But you're only guaranteeing that to yourself. It doesn't form part of the interface contract so it's no use to anybody else. Which is the bigger picture.
    Whenever i use any anonymous classes i prefer to use the final variables as long as i dont need to change their values.No you don't 'prefer' it, you are forced to do that by the compiler.

  • Use of const keyword in java ?

    Hi All,,
    I want to know the use of const keyword with proper example.
    Many many thx in advance
    Cheers
    Souvik

    I want to know the use of const keyword with proper example.
    There is no proper example, because const is not used in Java. If you want to create a constant, use the final keyword.

  • Use of 'static' keyword in synchronized methods. Does it ease concurrency?

    Friends,
    I have a query regarding the use of 'synchronized' keyword in a programme. This is mainly to check if there's any difference in the use of 'static' keyword for synchronized methods. By default we cannot call two synchronized methods from a programme at the same time. For example, in 'Program1', I am calling two methods, 'display()' and 'update()' both of them are synchronized and the flow is first, 'display()' is called and only when display method exits, it calls the 'update()' method.
    But, things seem different, when I added 'static' keyword for 'update()' method as can be seen from 'Program2'. Here, instead of waiting for 'display()' method to finish, 'update()' method is called during the execution of 'display()' method. You can check the output to see the difference.
    Does it mean, 'static' keyword has anything to do with synchronizaton?
    Appreciate your valuable comments.
    1. Program1
    public class SynchTest {
         public synchronized void display() {
              try {
                   System.out.println("start display:");
                   Thread.sleep(7000);
                   System.out.println("end display:");
              } catch (InterruptedException e) {
                   e.printStackTrace();
         public synchronized void update() {
              try {
                   System.out.println("start update:");
                   Thread.sleep(2000);
                   System.out.println("end update:");
              } catch (InterruptedException e) {
                   e.printStackTrace();
         public static void main(String[] args) {
              System.out.println("Synchronized methods test:");
              final SynchTest synchtest = new SynchTest();
              new Thread(new Runnable() {
                   public void run() {
                        synchtest.display();
              }).start();
              new Thread(new Runnable() {
                   public void run() {
                        synchtest.update();
              }).start();
    Output:
    Synchronized methods test:
    start display:
    end display:
    start update:
    end update:
    2. Program2
    package camel.java.thread;
    public class SynchTest {
         public synchronized void display() {
              try {
                   System.out.println("start display:");
                   Thread.sleep(7000);
                   System.out.println("end display:");
              } catch (InterruptedException e) {
                   e.printStackTrace();
         public static synchronized void update() {
              try {
                   System.out.println("start update:");
                   Thread.sleep(2000);
                   System.out.println("end update:");
              } catch (InterruptedException e) {
                   e.printStackTrace();
         public static void main(String[] args) {
              System.out.println("Synchronized methods test:");
              final SynchTest synchtest = new SynchTest();
              new Thread(new Runnable() {
                   public void run() {
                        synchtest.display();
              }).start();
              new Thread(new Runnable() {
                   public void run() {
                        synchtest.update();
              }).start();
    Output:
    Synchronized methods test:
    start display:
    start update:end update:
    end display:

    the synchronized method obtain the lock from the current instance while static synchronized method obtain the lock from the class
    Below is some code for u to have better understanding
    package facado.collab;
    public class TestSync {
         public synchronized void add() {
              System.out.println("TestSync.add()");
              try {
                   Thread.sleep(2000);
              } catch (InterruptedException e) {
                   e.printStackTrace();
              System.out.println("TestSync.add() - end");          
         public synchronized void update() {
              System.out.println("TestSync.update()");
              try {
                   Thread.sleep(2000);
              } catch (InterruptedException e) {
                   e.printStackTrace();
              System.out.println("TestSync.update() - end");          
         public static synchronized void staticAdd() {
              System.out.println("TestSync.staticAdd()");
              try {
                   Thread.sleep(2000);
              } catch (InterruptedException e) {
                   e.printStackTrace();
              System.out.println("TestSync.staticAdd() - end");
         public static synchronized void staticUpdate() {
              System.out.println("TestSync.staticUpdate()");
              try {
                   Thread.sleep(2000);
              } catch (InterruptedException e) {
                   e.printStackTrace();
              System.out.println("TestSync.staticUpdate() - end");
         public static void main(String[] args) {
              final TestSync sync1 = new TestSync();
              final TestSync sync2 = new TestSync();
              new Thread(new Runnable(){
                   public void run() {
                        sync1.add();
              }).start();
              new Thread(new Runnable(){
                   public void run() {
                        sync2.update();
              }).start();
              try {
                   Thread.sleep(3000);
              } catch (InterruptedException e) {
                   e.printStackTrace();
              new Thread(new Runnable(){
                   public void run() {
                        sync1.staticAdd();
              }).start();
              new Thread(new Runnable(){
                   public void run() {
                        sync2.staticUpdate();
              }).start();
    }

  • How to use knowledge base keywords"?

    I have found links to the the knowledge base document "how to use knowledge base keywords" online but all the links lead to a dead end. The document number is 75178, and explains the use of prefixes in the knowledge base keyword search. Has anyone any info on where this page is or if it still exists?
    Thanks
    Nadya

    Apparently, the document's no longer available.

  • Use VB Set keyword with Clone method?

    I am using the TestStand API with Visual Basic 6.0 SP5. Is is necessary to use the Set keyword when calling the Clone method of a PropertyObject? i.e. which is correct:
    Set thePropObj = existingPropObj.Clone("", 0)
    or
    thePropObj = existingPropObj.Clone("", 0)
    Seems the Set keyword would be required, but I am
    running into funny problems with this. I have a step
    that I am trying to create a copy of. (The step contains a call to a LabVIEW VI.) If I omit the Set keyword, execution hangs at the call to Clone. If I include the Set keyword, all information present in the original PropertyObject doesn't seem to get copied to the new one. (Also, oddly enough, if I omit the set keyword, and the step calls a CVI function, everything seems to work
    fine!)
    Anyone have any advice?
    Thanks in advance
    D. LaFosse

    Hello LaFosse,
    You need to use the Set keyword before the clone method statement. However, I have a couple of comments about the code you sent.
    This is the code you sent:
    ' Start up the testStand engine
    Dim theTS As TS.Engine
    Set theTS = New TS.Engine
    ' OK, load in the sequence file I
    ' created. This sequence file
    ' contains nothing more than a call
    ' to a VI in the main stepgroup of
    ' the MainSequence.
    Dim seqFile As SequenceFile
    Set seqFile =
    theTS.GetSequenceFile()
    ' get a handle to the MainSequence
    Dim seq As Sequence
    Set seq = seqFile.GetSequenceByName
    ("MainSequence")
    ' Get a handle to the step that calls
    ' the VI, and a property object for
    ' the step
    Dim theStep As Step
    Set theStep =
    seq.GetStep(0, StepGroup_Main)
    Dim theStepProp As PropertyObject
    Set theStepProp =
    theStep.AsPropertyObject
    ' Create another step. We will attempt
    ' to use Clone to fill in the
    ' properties of this step.
    Dim theOtherStep As Step
    Dim theOtherStepProp As PropertyObject
    Set theOtherStep = theTS.NewStep("",
    TS.StepType_Action)
    Set theOtherStepProp =
    theOtherStep.AsPropertyObject
    ' Call clone...this step will hang.
    theOtherStepProp =
    theStepProp.Clone("", 0)
    Basically the problem is that you are not loading the TypePallete after creating the engine. You shoud include right after the Set theTS = New TS.Engine:
    theTS.LoadTypePaletteFiles
    This should avoid the crash.
    Some Additional comments:
    1. With VB you don't need to create property objects from other objects. All the classes, except the Engine Class, inherit from the Property Object Class. The following Code does the same thing, but without creating propertyobjects directly:
    Sub MySub()
    'Variable Declaration
    Dim theTS As TS.Engine
    Dim seqFile As SequenceFile
    Dim seq As Sequence
    Dim theStep As Step
    Dim theOtherStep As Step
    'Create the Engine
    Set theTS = New TS.Engine
    'Load the Types
    theTS.LoadTypePaletteFiles
    'Get Sequence File
    Set seqFile = theTS.GetSequenceFile()
    'Get Sequence
    Set seq = seqFile.GetSequenceByName("MainSequence")
    'Get Step
    Set theStep = seq.GetStep(0, StepGroup_Main)
    'Clone the Step
    Set theOtherStep = theStep.Clone("", 0)
    'Using the inheritance functionality
    'gets the Step Status
    'Notice that theOtherStep is not a PropertyObject
    'and you can use all the properties and methods that
    'applies to the PropertyObject Class to a Step class
    'in this example
    'Also, in VB when you are typing the statement, you
    'will not see the PropertyObject Class properties and
    'and Methods automatically if the variable is not a
    'PropertyObject type. However, you can still use them
    'as mentioned before
    MsgBox (theOtherStep.GetValString("Result.Status", 0))
    End Sub
    2. When you create or modify sequence files programatically be carefull not to break the license Agreement. You need the development lisence when modifying sequences.
    3. This piece of code is not completed, and you will need to shutdown the engine by the end.
    4. Since you are not handling UI Messages, you will need to be carefull when loading sequences that have the SequenceFileLoad Callback. The engine posts UI Messages when executing this callback. Also when you shutdown the engine, UI Messages are posted. For both operations (Load Sequence and Shuutdown) you may prevent the engine from posting the message (You may check the options parameter for this two methods in TS Programmer Help.)
    5. If you want to run a sequence, again you will need to incorporate in your code the UIMessage Handler part. (You may check the TS Programmer Help->Writing an Application Using the API->UI Messages). Otherwise it may hang since the engine posts UI Messages eventually.
    Regards,
    Roberto Piacentini
    National Instruments
    Applications Engineer
    www.ni.com/support

  • What is the Use of Abstraction

    What is the Use of Abstract class..
    Edited by: Deenu on Jul 1, 2008 11:11 PM

    Deenu wrote:
    What is the Use of Abstract class..It's highly effective in confounding lazy noobs.
    Instead of posting every question that pops into your mind and waiting for somebody to spoonfeed you the answer, you might find it useful to go through one or more tutorials or texts on Java. For instane, perhaps one or more of the following might be useful.
    Sun's [basic Java tutorial|http://java.sun.com/docs/books/tutorial/]
    Sun's [New To Java Center|http://java.sun.com/learning/new2java/index.html].Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    [http://javaalmanac.com|http://javaalmanac.com]. A couple dozen code examples that supplement [The Java Developers Almanac|http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance].
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's [Thinking in Java|http://mindview.net/Books/DownloadSites] (Available online.)
    Joshua Bloch's [Effective Java|http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683/ref=pd_bbs_1?ie=UTF8&s=books&qid=1214349768&sr=8-1]
    Bert Bates and Kathy Sierra's [Head First Java|http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance].
    James Gosling's [The Java Programming Language|http://www.bookpool.com/sm/0321349806]. Gosling is
    the creator of Java. It doesn't get much more authoratative than this.

  • Using the 'this' keyword

    What is the use of the this keyword:
    import java.util.*;
    public abstract class LegalEntity implements HasAddress{
    private String address;
    private String area;
    private String registrationDate;
    private ArrayList accounts;
    public LegalEntity()
         accounts = new ArrayList();
    public void addAddress(String address){this.address = address;}
    public String getAddress(){return address;}
    public void addAccount(Account account)
         accounts.add(account);
    public ArrayList returnAccounts()
         return accounts;
    }

    This can be used when there are lots of static functions and you want to be sure you are invoking the current objects methods/members.

  • Using the LIKE keyword in a SQL query

    Does anyone have an example using the Database Connectivity Execute Query vi and the LIKE keyword? I would like to do something like:
    SELECT TestNum, TestType FROM tests WHERE DeviceType ='Paul_AF125_Ver1' AND DeviceID = 'Test1' AND (TestType LIKE "Cyclic Voltammetry*")
    It works fine if I say LIKE "Cyclic Voltammetry" (without the *) but if I put the * in there, I get no records.
    I'm using Microsofts SQL Server Desktop Engine (comes with Access).
    Thanks,
    Paul

    Paul-
    Thank you for contacting National Instruments. I don't have an example program, but I did find some information for you.
    LIKE - similar to.
    Using the LIKE command, you can use the wildcard symbol %. To find names starting with J : names LIKE 'J%'; Ending in s ? name LIKE '%S'; You can use more than one % charactor too : names LIKE '%sam%'; Also, LIKE is not case sensitive.
    What you have written, may work if you change the wildcard syntax from * to %.
    -Erik

Maybe you are looking for

  • Re: [iPlanet-JATO] Re: Use Of models in utility classes - Pease don't forget about the regular expression potential

    Namburi, When you said you used the Reg Exp tool, did you use it only as preconfigured by the iMT migrate application wizard? Because the default configuration of the regular expression tool will only target the files in your ND project directories.

  • Digital Booklet "Damaged or corrupted" in Adobe Reader X?

    I purchased La Roux (Gold Edition) this morning. All of the files downloaded fine, but I cannot open my digital booklet. Am I the only one having this issue? can it be fixed?

  • How to protect my images

    Hi, Here is my web app file structure: Tomact Webapps MyApp WEB-INF jsp >>>>>> 1.jsp >>>>>>2.jsp To protect my jsps from direct access from users, I put them under WEB-INF. Here is my 1.jsp <html> <body> <img src="1.jpg"/> <img src="2.jpg"/> </body>

  • 2014 Mac Pro, 12-core vs 8-core

    I regards to Adobe CC performance, I am weighing between Apple's new Mac Pro 8-core and 12-core options, with dual AMD Firepro d700 GPUs, without a red-rocket.  I would like this computer to be a 7-ish year computer, or longer.  I understand the 8-co

  • LOSS ALL FORUM SETTINGS

    What in the world happened to all the forums I was subscribed too? I see nothing when I go to discussion forums that I had selected just yesterday and see no way to get to the forums I had before. WHAT IS THIS MESS ANYWAY?????