Can Applet have constructors?
Answers were Sorted based on User's Feedback
Answer / rohit chhabra
usualy applets hv no contructors coz we do't need to create
object of the applet class...
but if one wants to create an object of an applet class,
create it in static block...This block execute before init
method..
Is This Answer Correct ? | 45 Yes | 4 No |
Answer / sunil dhadwe
In Java, every class has constructor, so Applet class also has constructor which is invoked when Applet object is created by browser or Applet Viewer. Usually we don't need constructor as we don't create Applet object.
To write applet we write our own class that extends Applet, so our class also becomes Applet. Our class can also have constructor. From our class we can call super class (Applet) constructor. Look at following code:
import java.applet.Applet;
import java.awt.Graphics;
/*
<applet code="AppletConst" width=400 height=300>
</applet>
*/
public class AppletConst extends Applet {
public AppletConst() {
super(); // no compilation error : means Applet class has constructor
System.out.println("Applet constructor");
}
public void paint(Graphics g) {
g.drawString("Hello world!", 50, 25);
}
}
Is This Answer Correct ? | 39 Yes | 3 No |
Answer / urusa
Applets do not have constructors because we don't need to create the object of the applet class....so its justified that it is true that applets usually do not have constructors
Is This Answer Correct ? | 12 Yes | 3 No |
Answer / roy antony arnold
Don't say like this....
Answer:
Applets don't usually have constructors because an applet
isn't guaranteed to have a full environment until its
init() method is called. For example, the Applet image
loading methods don't work inside an applet constructor, but
can be called from the init() method.
Is This Answer Correct ? | 12 Yes | 8 No |
Answer / therathna
In Java For Every Class we can provide constructors so
o busily we can provide constructors for applets.
u Don't ask like this type of questions because we can
pratically found these questions when done programs
u ask only questions like which are not practically unable
to do
Is This Answer Correct ? | 5 Yes | 23 No |
What is meant by polymorphism?
Is it possible to write JAVA program without including any of the packages,such as "import java.io.*"; bcoz I instantly wrote a code without "import..." statement and runned the program on command Line & it worked. the code is: class Person { String name; int age; Person(String s,int a) { name = s; age = a; } accept() { System.out.println(name+"Hi!!!!!"); System.out.println(age); } } class Demo { public static void main(Strings args[])throws IOException { String name = args[0]; int age = Integer.parseInt(args[1]); Person p = new Person(name,age); p.accept(); } }
How to declare unique ArrayList ?
What is Generic in java? Where can we write Generic ( class or method or objects or etc...)? with simple example? Thanks, Bose.
2 Answers Infosys, Tech Mahindra,
What is the mapping mechanism used by java to identify IDL language?
Where are the card layouts used?
What is mnemonic in assembly language?
Where are the local variables stored?
how to split string in java?
Why string is a class?
how a programmer confirms that the data submitted has been succesfully inserted into the database(either oracle or my sql).. How a programmer confirm if there is any problem with the program he wrote for insertion... ANS:--- >executeupdate method is having boolean return type, if anything goes wrong in data insertion or data updation, it would return false. otherwise, if it successfully inserts data into the database, it would return true NOW HOW TO I CHECK IN MY DURING EXECUTION WHETHER IT RETURNS TRUE OR FALSE... WELL IT WILL DISPLAY ANY MESSAGE OR NOT
What type of value does sizeof return?