Skip to content

Instantly share code, notes, and snippets.

View Devansh-Maurya's full-sized avatar
Up and up and up...

Devansh Maurya Devansh-Maurya

Up and up and up...
View GitHub Profile
class A {
//...
}
//class B inherits class A
class B extends A {
//...
}
//class C inherits B, which in turn, inherits A
final class A {
//...
}
//The following class is illegal
class B extends A { // ERROR! Can't subclass A
//...
}
protected void finalize() {
//finalization code here
}
@Devansh-Maurya
Devansh-Maurya / final_method.java
Last active September 30, 2018 03:41
Example showing how final prevents method overriding
class A {
final void meth() {
System.out.println("This is a final method");
}
}
class B extends A {
void meth() { // ERROR! Can't override.
System.out.println("Illegal!");
}
Intent intent = getIntent();
currentPetUri = intent.getData();
if (currentPetUri == null) {
setTitle("Add a new pet");
} else {
setTitle("Update pet data");
// Initialize a loader to read the pet data from the database
// and display the current values in the editor
getLoaderManager().initLoader(EXISTING_PET_LOADER, null, this);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(CatalogActivity.this, EditorActivity.class);
startActivity(intent);
}
});
ListView petListView = findViewById(R.id.list);
petListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Intent intent = new Intent(CatalogActivity.this, EditorActivity.class);
Uri currentPetUri = ContentUris.withAppendedId("content://com.example.android.myapplication/pets", id);
intent.setData(currentPetUri);
startActivity(intent);
}
ContentUris.withAppendedId("content://com.example.android.myapplication/pets", id);