Why only one Class is public in one file? Explain in
details. Thanks in Advance.

Answer Posted / sadhi

In java we have 4 specifiers i.e:
1.public
2.private
3.protected
4.default
public: we can access these instance variables and instance
methods at out side the class and inside the class.
2.private:using this specifier only we can access with in
the class. there is no possibility to access the outside.
3.protected:we can access the class with in the package.
4.default:Is generally act as public when we not specify
anything specifier.

so,we can use public class any where that mean these
variables and methods accessed by another class that's why
there is no need to create more public classes in single file

Is This Answer Correct ?    8 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain enumeration in java?

573


How many static init can you have?

690


Can a class be private?

520


What exactly is java?

519


Difference between a process and a program?

619






Can extern variables be initialized?

516


Is java a pure object oriented language?

542


What is methods and methodology?

538


What is navigable map in java?

527


Explain the advantages of packages in java?

517


What is protected in java?

533


Can we modify the throws clause of the superclass method while overriding it in the subclass?

553


Can a vector contain heterogenous objects?

607


what is enumset?

589


What access modifiers can be used for methods?

563