Generally to declare the class we use the public,abstract,final,strictfp and default modifiers.
When ever we declare the class as public ,it mean
public class A{}
it is possible to access this class inside the same package and outside of the current package.
ex:
package name: pack
This package contain the public class like
package pack;
public class A{}
In this senario it is possible to access the in the same package "pack" like
package pack;
class Demo {
public static void main(String args[]) {
A a=new A();
}
}
And also it is posible to access the A class outside of the "pack" package like
in anothe package like "pack1"
package pack1;
import pack.A;
class Demo1 {
public static void main(String args[]) {
A a=new A();
}
}
no you can have a class with no public methods and even with a a private constructor public class Example { //constructor private Example(){ } }
not exactly..... only If your class is public then the java program name should be the public class name with extension Sample.java >> public class Sample { public static void main(String[] args) { ..... } } NonPublicClass.java class SomeOtherName { ......... }
default it is public type
It is not compulsory that the java file name and name of the public class should be same. if u will give java file name and public class name different then u have to compile and run the program with another names. for example: u have named class sample i.e. (public class sample) and main function is also defined in this class. and u have saved the file as abc.java then u will first comple the file as: javac abc.java now run the file (type java class name(in which main function is defined) i.e. java sample try it.
No. There can be multiple java classes in the same .java file, but the name of the file must match the name of the public class in the file.
The name of the .java file should exactly match with the name of the public class in the file. Ex: public class Test { ..... } this file should be saved as Test.java
You can create a Thread in Java by using two ways. 1. Extending the Thread class public class Test extends Thread { ..... } 2. Implementing the Runnable Interface public class Test implements Runnable { ... }
Yes, it can. However, there can only be one public class per .java file, as public classes must have the same name as the source file.
You would make a class Final in Java if you do not want anybody to inherit the features of your class. If you declare a class as Final, then no other class can extend this class. Example: public final class X { .... } public class Y extends X { .... } Here Y cannot extend X because X is final and this code would not work.
Java source files have the .java extension, compiled Java class files have the .class extension.
Ex: public class A { ... } public class B extends A { ... } public class C extends B { ... } Here class C extends B which in turn extends A so class C indirectly extends class A.
Apache Harmony is the recent open source implementation of the Java runtime with class libraries and associated tools.