What are Class declarations and Modifiers in Java

A class in Java can be declared as shown below

class SampleApp { }

The above class does not specify any modifiers but in general most of the Java classes declaration will be specified with modifiers. The different modifiers that are allowed in java class declarations are

Access Modifiers

  • public
  • protected
  • private

Non Access Modifiers

  • strictfp
  • final
  • abstract

Access Modifiers talk about the visibility of the java class from other other classes. A class needs to access another class to create an instance of the another class or extend the class or access methods  and variables from another class.

public default protected private
class Thumbs up Thumbs up Thumbs up Thumbs up
package Thumbs up Thumbs up Thumbs up Thumbs down
subclass Thumbs up Thumbs down Thumbs up Thumbs down
java universe Thumbs up Thumbs down Thumbs down Thumbs down

The non access modifiers does the following

Final  – Prevents a class from being extended and the cannot be sub classed

strictfp – The floating points  used in the class will behave in platform independent way.

abstract – A class declared abstract must be extended and can never be instantiated.

In Category: Java, Programming

Ravi Shankar

A Software developer and blogger who is always looking to provide technical help to the wider community.

Show 0 Comments
No comments yet. Be the first.

Leave a Comment

Get your free copies of the following tech guides by joining the Digital Answers mailing list.